【问题标题】:UITableView as inputView for UITextField didSelectRowAtIndexPath randomly not firedUITableView 作为 UITextField didSelectRowAtIndexPath 的 inputView 随机未触发
【发布时间】:2015-12-17 18:54:44
【问题描述】:

我有一个 UITableViewController 用来覆盖 UITextField 子类的 inputView。有时 tableView didSelectRowAtIndexPath 停止被触发,直到用户 scoll 表并尝试再次单击。我似乎无法解决导致细胞无反应的原因。大多数时候它工作得很好,但随机单元格停止响应触摸,直到用户稍微滚动一下表格视图。

据我所知,我的视图中没有任何 TapGestureRecognizers,并且尝试过在 UITableViewCell 中覆盖 HitTest,但似乎无法解决问题。

关于如何更好地调试的任何想法?

这里是tableView控制器代码:

protocol MultiSelectPickerDelegate
{
    func didSelectOption(optionIndex:Int, group:Int)
}

class MultiSelectPicker: UITableViewController {

    var multiSelectGroups = [MultiSelectGroup](){
        didSet{
            self.tableView.reloadData()
        }
    }


    var delegate:MultiSelectPickerDelegate?

    // MARK: - Table view data source

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return multiSelectGroups.count

    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return multiSelectGroups[section].multiSelectOptions.count
    }


    //MARK: UITableView datasourse function
    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        delegate?.didSelectOption(indexPath.row, group: indexPath.section)
    }

    override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let view = UIView(frame: CGRectMake(0, 0, tableView.frame.size.width, 40))
        let label = UILabel(frame: CGRectMake(10, 0, tableView.frame.size.width, 40))
        label.font = UIFont.systemFontOfSize(14)
        label.text = multiSelectGroups[section].name
        label.textColor = UIColor.whiteColor()
        view.addSubview(label)
        view.backgroundColor = UIColor.MyAppBlue()
        return view

    }

    override func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 40
    }

     override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        var cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier")
        if cell == nil{
            cell = UITableViewCell(style: .Default, reuseIdentifier: "reuseIdentifier")
        }
        cell?.textLabel?.text = multiSelectGroups[indexPath.section].multiSelectOptions[indexPath.row].name
        return cell!
    }
}

【问题讨论】:

  • 您将 MultiSelectPicker.view 分配给 UITextField.inputView ?

标签: swift uitableview uitextfield didselectrowatindexpath


【解决方案1】:

我遇到了同样的问题。在我的表格视图中,它没有在第一次点击时单击表格的最后一行。它突出显示它,但没有调用 didSelectRowAtIndexPath。所有其他行工作正常。但是如果我打开 tableview 弹跳,那么它似乎可以解决问题

还可以尝试在 Interface Builder 中删除 Show Selection on Touch,如下所示:

希望对你有帮助

【讨论】:

  • 试过这个,好像没什么区别。感谢您的建议。
  • 我的同事注意到 UITableView 中的弹跳似乎导致行选择暂时停止工作。我禁用了弹跳,但问题尚未再次出现。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-09-03
  • 2014-01-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多