Re: [問題] reloadRowsAtIndexPath exception
※ 引述《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)
討論串 (同標題文章)
MacDev 近期熱門文章
PTT數位生活區 即時熱門文章