2017-10-05 1 views
-1

UiTableView에 대한 작업을 삭제하기 위해 스 와이프를 구현하고 있습니다. 제대로 작동하는 테이블을 만들었습니다. 그러나 테이블보기에서 항목을 클릭하면 didSelectRowAt이 호출되지 않습니다. 로그를 인쇄하지 않습니다.UiTableView didSelectRowAt 메서드가 호출되지 않았습니다.

enter image description here

코드 것은

class ManageUsersTable: UIViewController, UITableViewDelegate, UITableViewDataSource { 

    @IBOutlet weak var editView: UIView! 
    @IBOutlet weak var main_user_table: UITableView! 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     // Do any additional setup after loading the view. 
     editView.isHidden = true 


    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     return 6 
    } 

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     let cell = Bundle.main.loadNibNamed("UsersTableCell", owner: self, options: nil)?.first as! UsersTableCell 
     cell.selectionStyle = UITableViewCellSelectionStyle.none 
     return cell 
    } 

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 
     print("selected : \(indexPath.row)") 
    } 

    func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { 
     return true 
    } 

    func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? { 
     print("Delete at index : \(indexPath.row)") 
     let delete = UITableViewRowAction(style: .destructive, title: "Delete") { (action, indexPath) in 
      // delete item at indexPath 
      print("Delete at index : \(indexPath.row)") 
      self.editView.isHidden = false 
     } 
//  let edir = UITableViewRowAction(style: .normal, title: "Edit", icon : UIImage()) { (action, indexPath) in 
//   print("Edit at index : \(indexPath.row)") 
//  } 
//  edit.backgroundColor = UIColor.darkGray 
//  return [delete, edit] 
     return [delete] 
    } 
    } 

어떤 사람이 날이 TNX를 해결하는 데 도움이 될 수 있습니다.

갱신

내가 왼쪽에서 오른쪽으로 스 와이프하면 방법은 작동합니다. 항목이 아님

+0

당신은 그것의 스토리 보드/펜촉에 ManageUsersTable에있는 tableview 대리자를 설정해야? –

+0

예. 델리게이트를 설정했습니다 –

+0

'userInteractionEnabled' 속성을 한 번 확인하십시오. – Buntylm

답변

0

내가

let tapOnScreen: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(ManageDevicestable.CheckTheTime)) 
     tapOnScreen.cancelsTouchesInView = false 
     managetable.addGestureRecognizer(tapOnScreen) 

당신의 viewDidLoad에서이 작업을 수행 해결책을 발견 추가 선택 방법

func CheckTheTime() -> Void { 
     print("tapped") 
    } 
0

다음 목록을 확인하십시오.

1

)는 UITableViewDelegate 또는 UITableViewDataSource

2)

override func viewDidLoad() { 
     super.viewDidLoad() 
     // Do any additional setup after loading the view. 
     editView.isHidden = true 

     main_user_table.allowsMultipleSelectionDuringEditing = false //UPDATE THIS LINE 
    } 

3으로 당신의 viewDidLoad를 업데이트하십시오)

을 다음과 같다 삭제 강타의 기본 동작을 설정하는 것을 잊지 말라가) 때 셀을 스 와이프하면 삭제 버튼이 표시됩니다.

이 기능은 사용자가 삭제 버튼을 클릭하면)

func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { 
     print("swipe") 
    return true 
} 

B라고이 연료 소모량은

func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { 
     if(editingStyle == UITableViewCellEditingStyle.delete) 
     { 
      print("Delete Pressed") 

     } 
     } 

C

라고합니다) 당신이 당신의 삭제 버튼이 표시가 이제 때 당신은에 눌러 삭제 버튼 자체가 아니라 삭제 버튼이 숨겨져 처음으로 메소드가 호출되지 않습니다.

이제 삭제 버튼이 숨겨져 있고 셀을 탭하기 만하면됩니다. 이제 당신의 기능은 다음과 같습니다.

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 
     print("didSelectRowAt(\(indexPath)") 
    } 

다른 동작을 원할 경우이 외에도이 기능을 사용할 수 있습니다. 그런 다음 UITableViewCell을 사용자 지정해야합니다.

다른 문제가 발생하는 경우 구현을 철저히 다시 확인하십시오.

관련 문제