我設置了一個異常斷點並出現錯誤unrecognized selector sent to instance
該實例是UITableViewCell本身。該應用程序使用CoreData,當UITextfield結束編輯時,我想將文本保存到NSManagedObject。Textfield沒有結束編輯崩潰應用程序
這裏是我的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;
已解決此問題。
而你的問題的標題幾乎崩潰了我的大腦......;) – summea 2013-03-15 20:44:39
請告訴我們完整的錯誤信息,並告訴我們它被引發的路線。該消息中有問題的方法/選擇器的名稱。 – 2013-03-15 20:45:05
對不起,您確實標記了該行。如果它實際上是一個UITableViewCell,則會出現問題,因爲它應該是MCSwipeTableViewCell。 UITableViewCell無法響應itemLabel。再次,請顯示完整的錯誤消息。 – 2013-03-15 20:47:11