テーブルビューのセルをスワイプするときに、Github MGSwipeTableCell
(https://github.com/MortimerGoro/MGSwipeTableCell)のオープンソースライブラリを公開しています。UITableViewCellを削除するとNSExceptionが発生する
スワイプで公開されたボタンをタップするとクラッシュする。私はここでボタンをタップしたときに呼び出されるべきでクロージャを定義します。
// 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
を引き起こしているかについてのアイデアとどのように私はそれを修正するのでしょうか?
私はこのライブラリには必要ではないと思います。このデモでは、代表的なテーブルビューデリゲートメソッドは使用していません:https://github.com/MortimerGoro/MGSwipeTableCell/blob/master/demo/MailAppDemoSwift/MailAppDemoSwift/MailViewController.swift – mlecoz