2017-07-06 3 views
0

ボタン、タイトルを表示するテーブルビューが1つあります。今私はcell.And上の画像でセルをチェックする/チェックを外す必要があります最後に何をチェックしてイメージのセルのタイトルは私が印刷する必要がありますか?複数のチェックボックスを選択し、チェックされた行のタイトルだけを印刷する

私のコード:

var selectedIndexPathArray = Array<NSIndexPath>() 

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 

     let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! BlockedTableViewCell 

     let pending = allnames?[indexPath.row] 

     cell.NameLabel.text = pending?.name 


     return cell 
    } 
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 
     selectedIndexPathArray.append(indexPath as NSIndexPath) 
     tableView.reloadData() 
    } 

マイセルチェックボックスのイメージ名:'checked.png' 'unchecked.png'

+0

セルを選択したときにセルのタイトルを印刷しますか? – Phyber

+0

はい、チェックしたいボタンメイジを変更する必要があります。複数のチェックボックスも選択されています。チェックセルのタイトルだけを印刷する必要があります。(注:最初にチェックして、このタイトルとすべては印刷されません) –

+0

あなたのUITableViewCell用のカスタムクラスを作成することができます。 – Phyber

答えて

0

更新イメージ:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 

      let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! BlockedTableViewCell 

      let pending = allnames?[indexPath.row] 

      cell.NameLabel.text = pending?.name 
      if selectedIndexPathArray.contains(indexPath) { 
      cell.checkboxBtn.setImage(UIImage(named:"checked.png"), for: .normal)   
      } else { 
      cell.checkboxBtn.setImage(UIImage(named:"unchecked.png"), for: .normal)   
      } 


      return cell 
     } 

印刷タイトル:

func printSelectedItems(){ 

    for indexPath in selectedIndexPathArray { 
     let item = allnames?[indexPath.row] 
     print(item.name) 
    } 
} 
関連する問題