无法将 NSString 对象复制到我的自定义对象的属性 Objective-c

发布于 2024-12-22 12:46:14 字数 416 浏览 1 评论 0原文

如何将 NSString 数据复制到自定义对象的 NSString 属性? 我有一个带有 NSString *textKDoctor *doctor 属性的对象问题。 KDoctor 是一个具有两个属性的对象:NSString *nameUIImage *photo

self.question.doctor.name=@"abc";
NSLog(@"doctorname: %@", question.doctor.name);

输出是:

医生姓名:(空)

为什么?我该如何解决这个问题?

How to copy NSString data to my custom object's NSString property?
I have an object question with NSString *text and KDoctor *doctor properties.
KDoctor is an object with two properties: NSString *name and UIImage *photo.

self.question.doctor.name=@"abc";
NSLog(@"doctorname: %@", question.doctor.name);

Output is:

doctorname: (null)

Why? How could I solve this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清风挽心 2024-12-29 12:46:14

我的猜测是 question.doctor != self.question.doctor

question == nil

question.doctor == nil

my guess is that question.doctor != self.question.doctor

or

question == nil

or

question.doctor == nil

套路撩心 2024-12-29 12:46:14

看来你的正确声明有问题。您是否像这样定义“问题”属性?

在您的标头中:

@class KonsQuestion
@interface YourClass : NSObject {
  KonsQuestion * _question; 
}
@property(nonatomic, retain) KonsQuestion * question;

在实现文件中:

@implementation YourClass
@synthesize question = _question


@end

在这种情况下,您应该始终使用 self.question 来使用生成的 getter 和 setter,并在 dealloc 方法中使用 [_question release]

It seems you have something wrong declaring the properly. Are you defining "question" property like this?

In your header:

@class KonsQuestion
@interface YourClass : NSObject {
  KonsQuestion * _question; 
}
@property(nonatomic, retain) KonsQuestion * question;

In the implementation file:

@implementation YourClass
@synthesize question = _question


@end

In this case you should use always self.question to use the getter and setters generated and use [_question release] in the dealloc method

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文