Iphone can';t将NSString对象复制到我的自定义对象';s属性目标-c
如何将Iphone can';t将NSString对象复制到我的自定义对象';s属性目标-c,iphone,objective-c,ios,nsstring,properties,Iphone,Objective C,Ios,Nsstring,Properties,如何将NSString数据复制到自定义对象的NSString属性? 我有一个关于NSString*text和KDoctor*doctor属性的对象问题。 KDoctor是一个具有两个属性的对象:NSString*name和UIImage*photo self.question.doctor.name=@"abc"; NSLog(@"doctorname: %@", question.doctor.name); 输出为: doctorname:(空) 为什么??我怎样才能解决这个问题呢?我猜是问
NSString
数据复制到自定义对象的NSString
属性?
我有一个关于NSString*text
和KDoctor*doctor
属性的对象问题。
KDoctor是一个具有两个属性的对象:NSString*name
和UIImage*photo
self.question.doctor.name=@"abc";
NSLog(@"doctorname: %@", question.doctor.name);
输出为:
doctorname:(空)
为什么??我怎样才能解决这个问题呢?我猜是
问题。医生!=self.question.doctor
或
question==nil
或
question.doctor==nil
我猜是question.doctor!=self.question.doctor
或
question==nil
或
question.doctor==nil
看来您在正确声明问题时出错了。你是这样定义“问题”属性的吗
在标题中:
@class KonsQuestion
@interface YourClass : NSObject {
KonsQuestion * _question;
}
@property(nonatomic, retain) KonsQuestion * question;
在实现文件中:
@implementation YourClass
@synthesize question = _question
@end
在这种情况下,您应该使用always self.question来使用生成的getter和setter,并在dealloc方法中使用[\u question release],似乎您在正确声明。你是这样定义“问题”属性的吗 在标题中:
@class KonsQuestion
@interface YourClass : NSObject {
KonsQuestion * _question;
}
@property(nonatomic, retain) KonsQuestion * question;
在实现文件中:
@implementation YourClass
@synthesize question = _question
@end
在这种情况下,您应该使用always self.question来使用生成的getter和setter,并在dealloc方法中使用[\u question release]。quesion.doctor为零:(但为什么?
-(id)initWithQuestion:(KonsQuestion*)questn{self.question=[[KonsQuestion alloc]init]autorelease];question.text=questn.text;return self;}
我的init有问题吗?@Oleg:你没有在我们看到的任何地方设置question.doctor。我检查过。quesion.doctor为零:(但是为什么?-(id)initWithQuestion:(KonsQuestion*)questn{self.question=[[KonsQuestion alloc]init]autorelease];question.text=questn.text;return self;}
我的init有什么问题吗?@Oleg:你没有在我们见过的任何地方设置question.doctor。