2016-11-30 64 views
0

我有一个UITableView显示联盟中球员列表的场景。当VC从另一个VC返回时,如何清除UITableVIew中的所有检查?

用户选择两个玩家来比较结果。当用户选择玩家时,显示一张支票。一旦用户选择了两个用户,就会呈现一个新的VC,显示两个玩家的结果。

在这个ResultsVC我有一个后退按钮,关闭ResultsVC,视图返回到原始VC。

在返回到这个originalVC支票旁边选择观看其中的玩家仍然可见。

如何重置所有检查时,该VC返回?

这是我原来的VC用的TableView代码:

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它。

我加入

cell.accessoryType = .none 

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

然后当返回视图所有检查被除去。

相关问题