2017-12-18 7 views
0

테이블 뷰의 셀을 스 와이프 할 때 Github MGSwipeTableCell (https://github.com/MortimerGoro/MGSwipeTableCell)의 오픈 소스 라이브러리를 사용하여 버튼을 나타냅니다.NSITableViewCell 삭제시 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은 전무하지 않고 올바른 섹션을 가지고 있으며, 행 번호 :

lldb) po self.friendListTableView.indexPath(for: cell)! 
▿ 2 elements 
    - 0 : 2 
    - 1 : 0 

모든이 NSException의 원인이 무엇에 대한 아이디어와 어떻게 고칠 수 있을까요? 애니메이션에있는 tableView로부터 행을 삭제, 수정 데이터 소스를 제하고 deleteRows를 호출하기 위해

답변

1
self.friendListTableView.beginUpdates() 
    your_dataSource.remove(at: self.friendListTableView.indexPath(for: cell)!) 
    self.friendListTableView.deleteRows(at: [self.friendListTableView.indexPath(for: cell)!]) 
    self.tableView.endUpdates() 

. 당신은 그것은 당신의 삭제 행 작업을 처리하는이 방법

func tableView(_ tableView: UITableView, commit editingStyle: 
       UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {  

    if editingStyle == .delete { 
     print("Deleted") 
     your_dataSource.remove(at: indexPath.row) 
     self.tableView.deleteRows(at: [indexPath], with: .automatic) 
    } 
} 

을 단순히 해당 행의 indexPath의 가치를 발견 행을 삭제하고 호출 할 경우 마지막으로 beginUpdatesendUpdates

0

에서 삭제 코드를 포장.

+0

저는이 라이브러리에 필요하지 않다고 생각합니다. 이 데모에서는 일반적인 테이블 뷰 대리자 메서드를 사용하지 않습니다. https://github.com/MortimerGoro/MGSwipeTableCell/blob/master/demo/MailAppDemoSwift/MailAppDemoSwift/MailViewController.swift – mlecoz