码迷,mamicode.com
首页 > 其他好文 > 详细

-[__NSCFNumber rangeOfCharacterFromSet:]: unrecognized selector sent to instance 0x7fa5216589d0

时间:2015-02-27 21:36:00      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:ios   ios开发   

这个算是类型的不匹配,就是把NSNumber类型的赋给字符串了自己还不知情,因为我的是测试,代码如下(viewController.m里面)

- (void)viewDidLoad {
    [super viewDidLoad];
    bankAccount = [[BankObject alloc] init];
    [bankAccount setValue:@"10" forKey:@"account"];
    [bankAccount addObserver:self forKeyPath:@"account" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:nil];
    
    _myLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 200, 100)];
    _myLabel.text = [bankAccount valueForKey:@"account"];
    _myLabel.textColor = [UIColor whiteColor];
    [self.view addSubview:_myLabel];
    
    _myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    _myButton.frame = CGRectMake(200, 300, 100, 50);
    _myButton.backgroundColor = [UIColor redColor];
    [_myButton addTarget:self action:@selector(changeAccount) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_myButton];
    
}

打断点,也是程序执行完viewDidLoad后才会崩,察觉不到_myLabel.text = [bankAccount valueForKey:@"account"];这个错误,改成_myLabel.text = [NSString stringWithFormat:@"%@",[bankAccount valueForKey:@"account"]];就可以了

-[__NSCFNumber rangeOfCharacterFromSet:]: unrecognized selector sent to instance 0x7fa5216589d0

标签:ios   ios开发   

原文地址:http://blog.csdn.net/rainshenji/article/details/43972355

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!