我已经设置了一个异常断点,并且得到错误unrecognized selector sent to instance
该实例是UITableViewCell本身。该应用程序使用CoreData,当UITextfield结束编辑时,我想将文本保存到NSManagedObject。
这是我的TableViewController中的textFieldDidEndEditing
方法:
- (void)textFieldDidEndEditing:(UITextField *)textField {
MCSwipeTableViewCell *cell = (MCSwipeTableViewCell *) textField.superview.superview;
TehdaItem *item = [self.fetchedResultsController objectAtIndexPath:[self.tableView indexPathForCell:cell]];
item.itemTitle = cell.itemLabel.text; //The exception gets thrown on this line
// itemLabel is a UITextField and itemTitle is a string attribute of TehdaItem the NSManagedObject
NSError *error;
[item.managedObjectContext save:&error];
if (![self.fetchedResultsController performFetch:&error]) {
// Replace this implementation with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
}
将<UITextFieldDelegate>
设置为我的TableViewController,并将其设置为UITextField的委托。无法弄清楚这里的问题是什么。
编辑:删除superview
中的上一次MCSwipeTableViewCell *cell = (MCSwipeTableViewCell *) textField.superview.superview;
来电已解决问题。
答案 0 :(得分:1)
显然,UITextField的超级视图的超级视图属于UITableViewCell类型,而不是您期望的MCSwipeTableViewCell对象。查看单元格的创建位置,最可能是cellForRowAtIndexPath和/或它是在inteface builder / storyboard编辑器中对原型单元格进行的类分配。