libc++abi.dylib: terminate_handler unexpectedly threw an exception錯誤

最近做長按消息氣泡彈出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];
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容