2017-12-25 11 views

答えて

0

あなたのクラスは、次に使用UITableViewControllerのサブクラスである場合:

override func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) { 
    print(indexPath.row) 
} 

チェックコード例:

class ViewController: UITableViewController { 

    override func viewDidLoad() { 
     super.viewDidLoad() 

    } 

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) 
     cell.textLabel?.text = "\(indexPath.row)" 

     cell.accessoryType = UITableViewCellAccessoryType.detailButton 
     return cell 
    } 

    override func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) { 
     print(indexPath.row) 
    } 

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

そして、それはUIViewControllerのサブクラスだ場合、あなたはそのための方法の前にoverrideは必要ありません。それは次のようになります:

func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) { 
    print(indexPath.row) 
} 

この場合、テーブルビューのUITableViewDataSourceUITableViewDelegateViewControllerを接続することを忘れないでください。

詳細はexampleを確認してください。

関連する問題