ios - UITableview 返回不正确的索引路径行

标签 ios swift uitableview

<分区>

我有一个非常简单的 5 行表格设置用于设置屏幕。每当单击第一个单元格时,它会突出显示但不会调用 didselectrow。如果我单击不同的行,该行将调用 did select 函数但返回不正确的行。然后我可以单击第一行,它会返回但也有一个不正确的行。我在项目中设置了几个与此类似的表,但它们没有这种行为。单元格正确突出显示,所以我不认为我有布局/ View 问题。我没有任何约束警告,当我使用 viewdebugger 时,我没有遇到任何覆盖表格单元格的 View 。感谢所有帮助!

let settingsArray:[String] = ["Notifications","Account","bar","Help","Privacy Policy"]

extension SettingsViewController: UITableViewDataSource,UITableViewDelegate {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return settingsArray.count
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        print("\(indexPath.row) setting \(settingsArray[indexPath.row])")
        if settingsArray[indexPath.row] != "bar" {
            let cell = tableView.dequeueReusableCell(withIdentifier: "settingOption") as! SettingsOptionCell
            cell.configure(setting: settingsArray[indexPath.row])
            self.settingsTable.rowHeight = 65
            cell.isUserInteractionEnabled = true
            return cell
        } else {
            let cell = tableView.dequeueReusableCell(withIdentifier: "settingBar")
            self.settingsTable.rowHeight = 70
            cell?.isUserInteractionEnabled = false
            return cell!
        }

    }

    func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
        print("clicked \(indexPath.row)")
}
}

最佳答案

替换

func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

关于ios - UITableview 返回不正确的索引路径行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54772925/

相关文章:

ios - 如何与我的应用程序共享选定的文本?

swift - 使用 NSKeyedArchiver 保存并加载回来的对象为零

ios - Swift Typhoon 组件属性注入(inject)不起作用

具有自定义对象的 Android 自定义 ArrayAdapter

ios tableViewCell.xib文件生成多个单元格

iPhone - 如何创建自定义相册并以编程方式为相机胶卷中的照片指定自定义名称?

ios - 按实体索引 Swift 对 NSSortDescriptor 进行排序

ios - 如何在 UITableView 单元格上的所需位置添加图像?

ios - Swift 中的 enumerateSubstringsInRange

ios - 将从 UIPicker 中选择的值分配给 Swift 中的 UITextField(以及如何显示和隐藏它)