我可以在scheduleCellEntries[indexPath.row]
函数中调用cellForRowAt
,但是在链接到按钮的@IBAction
函数中,这是不可能的。
运行代码时,出现以下错误:Use of unresolved identifier 'indexPath'; did you mean 'IndexPath'?
我尝试按照错误中建议的方式进行操作,但这也不起作用。
数组:
var scheduleCellEntries: [ScheduleCell]! = [ScheduleCell(id: 1, textButtonState: false, timeButtonState: false, text: "Appointment", time01: "07:30", time02: "12:30")
cellForRowAt
功能:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if tableView == scheduleTableView {
let cell = tableView.dequeueReusableCell(withIdentifier: "scheduleCell", for: indexPath) as! scheduleTableViewCell
if scheduleCellEntries[indexPath.row].timeButtonState == false{
cell.scheduleDateCheckBox.isSelected = false
}else{
cell.scheduleTextCheckBox.isSelected = true
}
if scheduleCellEntries[indexPath.row].textButtonState == false{
cell.scheduleTextCheckBox.isSelected = false
}else{
cell.scheduleTextCheckBox.isSelected = true
}
return cell
}
@IBAction
功能:
@IBAction func timeCheckboxIsPressed(_ sender: UIButton) {
if sender.isSelected {
sender.isSelected = false
scheduleCellEntries[indexPath.row].timeButtonState = false
} else {
sender.isSelected = true
scheduleCellEntries[indexPath.row].timeButtonState = true
}
}
我想评估该函数中的数组,以便每当切换按钮状态时,数组中的布尔值也会更改。