我有一個實施UITableView
的基於iOS 6的項目。表格視圖中的每個單元格都包含允許用戶輸入信息的UITextField
。如果用戶在點擊另一個單元格(文本字段)時清除了文本字段或刪除了字段中的所有輸入(即[textfield length] == 0
),它將從表格視圖中刪除之前的單元格(文本字段),因爲它是空的 - 這可以避免在表格視圖中積累空單元格。嘗試刪除包含拒絕辭職的第一響應者的行
這是所有做用一種叫做-textFieldEditingDidEnd:
方法,其觸發的UIControlEventEditingDidEnd
事件的文本字段:
- (void)textFieldEditingDidEnd:(UITextField *)textField {
NSIndexPath *indexPath = // Index path of the row in the table view
if ([textField.text length] == 0) {
// Delete the cell from the table view
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
}
然而,當代碼與在控制檯上顯示以下信息發射應用程序崩潰:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Attempt to delete row containing first responder that refused to resign'
我以前從未見過此消息,並有不似乎是它特別多引用在網上搜索時。我將不勝感激任何有關如何解決此問題的建議。
嘗試把[textField resignFirstResponder];在刪除行之前,看看是否有幫助。 – Bergasms
謝謝,但之前嘗試過。不走,同樣的問題。 – Skoota