在一个未扣扣子的动作中进入一个牢房,导致迅速崩溃


@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)
}

我在加载表视图之前点击了按钮,所以崩溃正在发生,有什么解决方案吗?

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

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

相关内容

  • 没有找到相关文章

最新更新