【发布时间】:2014-10-02 19:54:17
【问题描述】:
我有一个名为friend 的NSObject 和另一个名为currentUser 的NSObject。 currentUser 里面有一个朋友类型的属性(friendToSendMimo)。但是每当我尝试为其设置另一个朋友对象时......应用程序崩溃并出现错误:'NSInvalidArgumentException',原因:'-[currentUser setFriendToSendMimo:]: unrecognized selector sent to instance 0x15d29810'
我的问题是:我怎样才能拥有来自 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];
}
【问题讨论】:
-
不是你的直接问题,而是为了让其他人阅读你的代码,你应该以大写字母开头你的类名。
-
根据您使用的 Xcode 版本,您可能需要在
@implementation中包含@synthesize friendToSendMimo;以获取currentUser。
标签: ios objective-c nsobject