2015-01-22 1 views
2

UITableView가 편집 모드이고 삭제 단추 (-)를 누르면 행의 편집 단추를 숨기고 삭제 및 취소 단추를 표시합니다.UITableView 편집 모드에서 단추를 제거 할 수 없습니다.

취소 버튼을 누르면 버튼의 취소 핸들러가 트리거되고 편집 버튼이 다시 표시되므로 정상입니다.

그러나 사용자가 행 (취소 또는 삭제 버튼 제외)을 누르면 편집 버튼을 표시하지 않고 행을 삭제 모드에서 종료합니다.

삭제 모드가 종료되거나 삭제 모드에서 행을 누르면 감지 할 수있는 이벤트가 있습니까?

func tableView(tableView: UITableView!, editActionsForRowAtIndexPath indexPath: NSIndexPath!) -> [AnyObject]! 
{ 
// hide the Edit button in this row 
self.editButtons[indexPath.row].hidden = true 

// create a Cancel button to abort delete 
var cancelAction = UITableViewRowAction(style: UITableViewRowActionStyle.Normal, title: "Cancel", handler: 
{( 
    action: UITableViewRowAction!, indexPath: NSIndexPath!) in 

// if Cancel pressed, show the Edit button again 
self.editButtons[indexPath.row].hidden = false 

// reload the row to get rid of the Delete and Cancel buttons 
tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic) 

return 
}) 

var deleteAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Delete",handler: 
{( 
action: UITableViewRowAction!, indexPath: NSIndexPath!) in 
    println("Delete not implemented") 
    return 
}) 
return [deleteAction, cancelAction] 
} 

답변

0

당신은 상태 변화를 추적하기 위해 UITableViewCell 내부의 willTransitionToState 기능을 대체 할 수 있습니다. 삭제 버튼이 숨겨져 있는지 확인하려면 previousState을 추적해야합니다.

class CustomCell : UITableViewCell 
{ 
    var previousState : UITableViewCellStateMask = UITableViewCellStateMask.allZeros 

    override func willTransitionToState(state: UITableViewCellStateMask) { 
     if state & UITableViewCellStateMask.ShowingEditControlMask != nil 
     { 
      if previousState & UITableViewCellStateMask.ShowingDeleteConfirmationMask != nil 
      { 
       println("hiding delete") 
       /* Send a notification or call a function by setting a 
        delegate from the view controller.*/ 
      } 

     } 
     previousState = state 
    } 
} 
+0

올바른 대답입니다. 편집 모드를 종료 할 때이 기능을 누르면됩니다. 그러나 나는 Swift를 처음 사용하기 때문에 View Controller에서 대리자를 설정하고 호출하는 방법을 알아야합니다. – billd

관련 문제