iOS 和 Stackmob - [NSNull 长度] : unrecognized selector sent to instance

标签 ios stackmob

在我的 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 对象。

关于iOS 和 Stackmob - [NSNull 长度] : unrecognized selector sent to instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17780378/

相关文章:

objective-c - 如何在回调 block 中异步创建 FetchRequest

ios - 我可以要求用户重新验证 Apple ID 登录吗

ios - 如何快速修复此 try/guard 错误

ios - 应用程序在其主键字段的对象 ID 的核心数据中崩溃

push-notification - 解析与 StackMob 与其他推送通知服务(Appcelerator 应用程序)

javascript - 从可编辑行获取值

iOS 6 - XCode 4.5.1 - iPad 模拟器 - 以编程方式获得错误的分辨率

ios - 无法更新核心数据中保存的数据

iOS MVVM 处理初始 View 状态

javascript - 回调时 stackmob 错误