最近做長按消息氣泡彈出menuController
刪除消息cell
功能遇到個錯誤,libc++abi.dylib: terminate_handler unexpectedly threw an exception
,這個異常沒有打印日志,也無法定位到具體問題。網絡找到這段代碼打印出異常:
@try {
//問題代碼
[self.dataArray removeObjectAtIndex:1];
[self.tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:1 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
[self.tableView endUpdates];
}
@catch (NSException *exception) {
NSLog(@"exception = %@", exception);
}
@finally {
}
輸出結果:
exception = Attempt to delete row containing first responder that refused to resign
看到這句話大概知道原因了,彈出menuController
需要設置becomeFirstResponder
成為第一響應者,刪除cell
之前則需要resignFirstResponder
刪除cell
之前加上這段代碼就好使了:
MessageCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]];
[cell.messageView resignFirstResponder];