Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone can';t将NSString对象复制到我的自定义对象';s属性目标-c_Iphone_Objective C_Ios_Nsstring_Properties - Fatal编程技术网

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。