2017-02-07 6 views
-1

を強調セルなしのセルを選択します。のUITableView編集 - 私は私のtableView細胞内のイメージを持っているので、私は、彼らが選択しているときに強調した細胞を避けるために、Noneに細胞selectionStyleを設定している

私は今、セルの左側にチェックマークcirleを埋める、ユーザーが複数のセルを選択することができ、のtableViewに編集を実装しようとしています。しかし、これはなしのselectionStyleで動作するようには思えない - 円はちょうど充填されていないまま。

これを解決する方法はありますか?

ありがとうございます。

答えて

0

セルを直接選択できない場合は、セルにuibuttonを配置して、タップされたボタンがどのセルにあるかを認識できます。これを行うには、buttonタグをindexPath.rowと同じに設定できますcellForRowAtIndexPathメソッド。

以下のコードは、正しい行番号を印刷します。お役に立てれば。

class MyTableViewCell: UITableViewCell { 

     @IBOutlet weak var onButton: UIButton! 

    } 

class ViewController: UIViewController,UITableViewDataSource,UITableViewDelegate { 

    @IBOutlet weak var tableView: UITableView! 
    override func viewDidLoad() { 
     super.viewDidLoad() 
    } 

    func buttonClicked(sender:UIButton) { 

     let buttonRow = sender.tag 
     print(buttonRow) 
    } 

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     return 4 
    } 
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCell(withIdentifier: "Cell") as! MyTableViewCell 

     cell.onButton.tag = indexPath.row 
     cell.onButton.addTarget(self, action: #selector(ViewController.buttonClicked(sender:)), for: .touchUpInside) 
     return cell 
    }} 
関連する問題