无法将 NSString 对象复制到我的自定义对象的属性 Objective-c
如何将 NSString
数据复制到自定义对象的 NSString
属性? 我有一个带有 NSString *text
和 KDoctor *doctor
属性的对象问题。 KDoctor 是一个具有两个属性的对象:NSString *name
和 UIImage *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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我的猜测是
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
看来你的正确声明有问题。您是否像这样定义“问题”属性?
在您的标头中:
在实现文件中:
在这种情况下,您应该始终使用 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:
In the implementation file:
In this case you should use always self.question to use the getter and setters generated and use [_question release] in the dealloc method