【发布时间】:2017-12-18 05:53:50
【问题描述】:
我正在使用 Github 上的开源库 MGSwipeTableCell (https://github.com/MortimerGoro/MGSwipeTableCell) 在滑动表格视图的单元格时显示按钮。
当我点击通过滑动显示的按钮时发生崩溃。我在这里定义了点击按钮时应该调用的闭包:
// This is in the library delegate method:
// func swipeTableCell(_ cell: MGSwipeTableCell, swipeButtonsFor direction: MGSwipeDirection, swipeSettings: MGSwipeSettings, expansionSettings: MGSwipeExpansionSettings) -> [UIView]?
// local variables: buttons, one of which is:
let rejectFriendReqButton = MGSwipeButton(title: "", icon: UIImage(named: "X"), backgroundColor: RED) { (cell) -> Bool in
DispatchQueue.main.async(execute: {
self.friendListTableView.deleteRows(at: [self.friendListTableView.indexPath(for: cell)!], with: .fade)
})
return FriendingCloudKitUtils.declineFriendRequest()
}
// In an if-else ladder:
else if direction == MGSwipeDirection.rightToLeft { // reject friend request
if section == 2 { // friend requests
if direction == MGSwipeDirection.leftToRight { // accept friend request
return [acceptFriendReqButton]
}
else if direction == MGSwipeDirection.rightToLeft { // reject friend request
return [rejectFriendReqButton]
}
}
else if self.friendListTableView.indexPath(for: cell)?.section == 4 { // in friend section
return [unfriendButton]
}
}
崩溃发生在我调用deleteRows 的那一行。我得到一个NSException。当我在 lldb 中执行 po $arg1 时,我得到:
error: Couldn't materialize: couldn't read the value of register x0
error: errored out in DoExecute, couldn't PrepareToExecuteJITExpression
我尝试了比我能跟踪的更多可能的解决方案,其中包括将按钮存储为全局变量而不是本地变量。
其他可能相关的说明:
当我进入调试模式时,表确实存在:
<UITableView: 0x10186c000; frame = (0 0; 375 554); clipsToBounds = YES; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x17425a760>; layer = <CALayer: 0x174236760>; contentOffset: {0, 0}; contentSize: {375, 357.5}>
正在解包的 indexPath 也不是 nil 并且具有正确的部分和行号:
lldb) po self.friendListTableView.indexPath(for: cell)!
▿ 2 elements
- 0 : 2
- 1 : 0
关于导致此NSException 的原因以及我如何解决它的任何想法?
【问题讨论】:
标签: ios swift uitableview lldb nsexception