繁体   English   中英

iOS和Stackmob - [NSNull length]:发送到实例的无法识别的选择器

[英]iOS & Stackmob - [NSNull length]: unrecognized selector sent to instance

在我的iOS应用程序中,我正在尝试更新数据库中的用户信息(使用Stackmob),但我不断收到“无法识别的选择器发送到实例”。

- (IBAction)save:(UIButton *)sender {

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"User"];
NSPredicate *predicte = [NSPredicate predicateWithFormat:@"username == %@", self.username];
[fetchRequest setPredicate:predicte];

[self.managedObjectContext executeFetchRequest:fetchRequest onSuccess:^(NSArray *results) {

    NSManagedObject *todoObject = [results objectAtIndex:0];
    [todoObject setValue:@"example@gmail.com" forKey:@"email"];

    [self.managedObjectContext saveOnSuccess:^{
        NSLog(@"You updated the todo object!");
    } onFailure:^(NSError *error) {
        NSLog(@"There was an error! %@", error);
    }];

} onFailure:^(NSError *error) {

    NSLog(@"Error fetching: %@", error);

}];
}

这是我得到的完整错误:

-[NSNull length]: unrecognized selector sent to instance 0x1ec5678

2013-07-21 12:01:25.773 [29207:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: '-[NSNull length]: unrecognized selector sent to instance 0x1ec5678'

提前致谢。

我想这可能是因为你的self.username是空的。 请注意,如果您从json获取用户名数据,则不能使用if(username){...}但是

if(![username isKindOfClass:[NSNull class]])

避免空数据,因为json解释器将生成一个NSNull对象。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM