进入取消按钮动作内的单元格会导致崩溃迅速

时间:2018-07-13 13:01:18

标签: ios swift uitableview

@IBAction func selectInviteBtnClicked(_ sender: UIButton) {

 let cell = matchedUsersTableView.cellForRow(at: IndexPath(row: sender.tag, section: 0)) as! MultiUserTableViewCell

if selectedUsers[sender.tag] == nil{
    selectedUsers[sender.tag] = true
}else if selectedUsers[sender.tag] == false{
    selectedUsers[sender.tag] = true
}else{
    selectedUsers[sender.tag] = false
}
var count = 0
for value in selectedUsers.values{
    if value{
        count += 1
    }
}
if count == (currentUserRide as! RiderRide).availableSeats + 1{
 UIApplication.shared.keyWindow?.makeToast(message: Strings.passengers_more_than_available, duration: 5.0, position: CGPoint(x: self.view.frame.size.width/2, y: self.view.frame.size.height-300))
}  

  setSelectButtonBasedOnSelection(isSelected:selectedUsers[sender.tag],button: cell.matchedUserSelectBtn)
}

我要在加载表格视图之前单击按钮,以便崩溃发生任何解决方案?

1 个答案:

答案 0 :(得分:1)

您需要检查单元格是否不是

guard let cell = matchedUsersTableView.cellForRow(at: IndexPath(row: sender.tag, section: 0)) as? MultiUserTableViewCell {
   return 
}
// use the cell