作者uranusjr (←这人是超级笨蛋)
看板MacDev
标题Re: [问题] reloadRowsAtIndexPath exception
时间Mon Nov 4 15:02:12 2013
※ 引述《peliuya (Unknown)》之铭言:
: 我有一个custom cell内包含了一个textField,
: 我希望在该textField编辑结束後, 单独更新该Cell
: 以下是我的程式码, 在编辑结束时
: - (BOOL) textFieldShouldReturn:(UITextField *)textField
: {
: [textField resignFirstResponder];
: return YES;
: }
: - (BOOL) textFieldShouldEndEditing:(UITextField *)textField
: {
: NSIndexPath *AlertPath = [NSIndexPath indexPathForRow:1 inSection:0];
: NSArray *myArray = [NSArray arrayWithObjects:AlertPath, nil];
: [self.functionTable reloadRowsAtIndexPaths:myArray
: withRowAnimation:UITableViewRowAnimationAutomatic];
: return YES;
: }
: 在执行到 reloadRowsAtIndexPaths 後 产生了一个exception
: Terminating app due to uncaught exception 'NSInternalInconsistencyException',
: reason: 'Attempt to delete row containing first responder
: that refused to resign'
: 若以 [self.functionTable reloadData] 来更新则是没有问题的
: 请问我该如何解决这个问题呢?
: 谢谢
当 textFieldShouldEndEditing 被呼叫时, text field 还没有结束编辑
这时候你还不能对包含它的 cell 进行 reload (正确来说应该是不能 remove)
不然程式就...嗯, 失去了 consistency
解决方法是不要在 textFieldShouldEndEditing: 直接呼叫 reload
而是要在它「结束之後」排定一个 reload 事件
最简单的解法(之一)是用 GCD 塞一个 async call
http://stackoverflow.com/questions/13907335/
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.112.94.57
※ 编辑: uranusjr 来自: 140.112.94.57 (11/04 15:02)