2016-11-30 2 views
0

私は、UITableViewがリーグ内の選手のリストを表示するシナリオを持っています。VCが別のVCから返されたときにUITableVIewのすべてのチェックをクリアするにはどうすればよいですか?

ユーザは、2人の選手を選択して結果を比較します。ユーザーがプレーヤーを選択すると、チェックが表示されます。ユーザが2人のユーザを選択すると、新しいVCが提示され、2人のプレーヤの結果が示される。

この結果では、私はResultsVCを終了する戻るボタンがあり、ビューは元のVCに戻されます。

この元のVCに戻った時点では、表示のために選択されたプレーヤーの横のチェックが引き続き表示されます。

このVCが返されたときにすべてのチェックをリセットするにはどうすればよいですか?

これは、テーブルビューと元のVCのために私のコードです:

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



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

    cell.textLabel?.text = self.communityPlayers[indexPath.row] 
    cell.textLabel?.font = UIFont(name: "Avenir", size: 12) 
    cell.textLabel?.textColor = UIColor.white // set to any colour 
    cell.layer.backgroundColor = UIColor.clear.cgColor 

    cell.personalStatsInfoButton.tag = indexPath.row 
    cell.personalStatsInfoButton.addTarget(self, action: #selector(infoClicked), for: UIControlEvents.touchUpInside) 

    cell.selectedBackgroundView?.backgroundColor = UIColor.red 

    return cell 

} 

func infoClicked(sender:UIButton){ 
    let buttonRow = sender.tag 
    self.friendId = self.communityPlayerIds[buttonRow] 
    self.personalSelf = false 
    self.friendName = self.communityPlayers[buttonRow] 
    self.performSegue(withIdentifier: "personalStatsSegue", sender: self) 
} 

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 

    self.selectedCellTitle = self.communityPlayers[indexPath.row] 
    cellId = indexPath.row 
    //print (self.communityPlayerIds[indexPath.row]) 

    if let cell = tableView.cellForRow(at: indexPath) { 
     if cell.isSelected { 
      cell.accessoryType = .checkmark 
     } 
    } 

    if let sr = tableView.indexPathsForSelectedRows { 
     print("didSelectRowAtIndexPath selected rows:\(sr)") 
     if sr.count == 2{ 
      let tempId_1 = sr[0][1] 
      let tempId_2 = sr[1][1] 
      self.tempCount = 2 
      self.tempPlayerId_1 = self.communityPlayerIds[tempId_1] 
      self.tempPlayerId_2 = self.communityPlayerIds[tempId_2] 

      print ("you have selected player I'ds: ", self.tempPlayerId_1!, "and ", self.tempPlayerId_2!) 
      self.performSegue(withIdentifier: "showHeadToHeadSegue", sender: self) 
     } 


    } 


} 

func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) { 

    if let cell = tableView.cellForRow(at: indexPath as IndexPath) { 
     cell.accessoryType = .none 
    } 

    if let sr = tableView.indexPathsForSelectedRows { 
     print("didDeselectRowAtIndexPath selected rows:\(sr)") 

    } 


} 
} 

私は主題を中心に読みましたが、何も動作するように表示されません。

答えて

0

sussed it。

Iはfunc tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell機能

cell.accessoryType = .none 

を追加ビューが返されたときに、すべてのチェックが除去されます。

関連する問題