在我的iOS應用程序中,我試圖更新數據庫中的用戶信息(使用Stackmob),但我一直收到「無法識別的選擇器發送到實例。iOS&Stackmob - [NSNull length]:發送到實例的無法識別的選擇器
- (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:@"[email protected]" 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'
在此先感謝。
一些你得到無值或對象,你試圖設置零,你爲什麼得到這個錯誤。檢查befor setValue是否爲零。 –
[ - \ [NSNull length \]的可能重複:無法識別的選擇器發送到...內存泄漏?](http://stackoverflow.com/questions/16607960/nsnull-length-unrecognized-selector-sent-to-一個內存泄漏) – borrrden
你可以打印self.username,看看它包含什麼? – satheeshwaran