首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UITableView作为UITextField didSelectRowAtIndexPath的inputView,随机未触发

问UITableView作为UITextField didSelectRowAtIndexPath的inputView,随机未触发
EN

Stack Overflow用户
提问于 2015-12-18 02:54:45
回答 1查看 1.1K关注 0票数 1

我有一个用来覆盖UITextField子类的inputView的UITableViewController。有时,tableView didSelectRowAtIndexPath会停止触发,直到用户收集该表并尝试再次单击。我似乎不能确定是什么导致细胞变得无反应。大多数情况下,它工作得很好,但随机的是,单元格停止对触摸的响应,直到用户滚动了一下表格视图。

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

对如何更好地调试它有什么想法吗?

下面是tableView控制器代码:

代码语言:javascript
复制
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!
    }
}
EN

回答 1

Stack Overflow用户

发布于 2015-12-18 14:42:33

我也有同样的问题。在我的表格视图中,第一次点击时并没有点击表格的最后一行。它高亮显示了它,但是didSelectRowAtIndexPath没有被调用。所有其他行都工作正常。但是,如果我打开tableview弹跳,那么问题似乎就解决了

​

​

同时尝试删除界面生成器中的Show Selection on Touch,如下所示:

​

希望能有所帮助

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34342175

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档