2014-10-02 153 views
0

我有一个名为friend的NSObject和另一个名为currentUser的NSObject。 朋友类型(friendToSendMimo)的currentUser中有一个属性。但每当我尝试设置另一个朋友对象...应用程序崩溃的错误:'NSInvalidArgumentException',原因:' - [currentUser setFriendToSendMimo:]:无法识别的选择发送到实例0x15d29810'在另一个NSObject中设置NSObject时,应用程序崩溃

我的问题是:我怎么能有一个来自NSObject的属性?

继承人的currentUser头:

#import "friend.h" 
@interface currentUser : NSObject<NSCoding> 

@property (nonatomic,strong)NSString *token; 
@property (nonatomic,strong)NSString *email; 
@property (nonatomic,strong)NSString *name; 
@property (nonatomic,strong)UIImage *userImg; 
@property (nonatomic,strong)NSString *username; 
@property (nonatomic,strong)friend *friendToSendMimo; //is there another way of setting this NSObject? 

和代码崩溃喜欢这里:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 
    //thisUser was set as currentUser 
    thisUser.friendToSendMimo = [thisUser.friendsList objectAtIndex:indexPath.row]; 

} 
+1

不是你的直接问题,但是对于其他人阅读你的代码,你应该用UpperCase字母开始你的类名。 – 2014-10-02 19:58:00

+0

根据你使用的Xcode版本的不同,你可能需要在''implementation''中为'currentUser'提供'@synthesize friendToSendMimo;'。 – 2014-10-02 20:00:19

回答

0

你例外的原因是 “无法识别的选择”。这通常意味着你要求它执行一个它不知道的方法。你有没有尝试在访问它之前分配和初始化friendToSendMimo属性?

+0

初始化并合成变量后...它工作!谢谢! – 2014-10-02 20:09:43

+0

很高兴帮助。更重要的是,你是否明白为什么你必须在尝试访问它之前先分配和初始化它? – 2014-10-02 20:11:58

相关问题