我在包含开关的Swift 4项目中创建了一个自定义单元格。当我选择任何开关时,我选择表格中的第10个开关。表格中有34个单元格。我尝试了许多不同的用户交互启用/禁用组合。即使未选定开关的状态显示为“开”,相关的动作也不会触发。下面是激发动作的代码:开关状态时,UISwitch在表格中选择多个单元格
@IBAction func SwitchAction(_ sender: UISwitch) {
let switchPosition = sender.convert(CGPoint(), to:tableView)
let indexPath = tableView.indexPathForRow(at:switchPosition)
let ipath = indexPath?.row
}
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return taskList.count
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 75
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
//let cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "Cell")
let cell: customTableViewCell = self.tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! customTableViewCell
cell.LabelSelect.text=taskList[indexPath.row]
return cell
}
欢迎来到堆栈溢出 - 很高兴有你。请阅读我如何提出一个好问题? https://stackoverflow.com/help/how-to-ask以及如何创建一个最小化,完整和可验证的示例,以帮助将堆栈溢出内容保持在最高级别,并增加获得正确答案的机会。 https://stackoverflow.com/help/mcve – 2017-10-20 01:41:37
你的开关动作是否给你正确的索引? – Tj3n
在cellforrowatindexpath方法中添加切换目标 – Vinodh