UITableView as inputView for UITextField didSelectRowAtIndexPath randomly not fired

爷,独闯天下 提交于 2019-12-24 14:34:59

问题


I have a UITableViewController that I'm using to override the inputView of a UITextField subclass. Sometimes the tableView didSelectRowAtIndexPath stops getting fired until a user scolls the table and tries to click again. I can't seem to get a fix on what would cause the cells to become unresponsive. Most of the time it works great, but randomly the cells stop responding to touches until the user scrolls the tableview a bit.

I don't have any TapGestureRecognizers in the view to my knowledge, and have played around with overriding HitTest in the UITableViewCell, but can't seem to figure out the issue.

Any ideas on how to better debug this?

Here is the tableView controller code:

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!
    }
}

回答1:


I was having same problem. On my table view it was not clicking very last row of my table on the first tap. It highlights it, but didSelectRowAtIndexPath isn't being called. All the other rows work fine. But if I turn the tableview bounce on then it seems to solve the problem

Also try removing Show Selection on Touch in Interface Builder as follows:

Hope it helps



来源:https://stackoverflow.com/questions/34342175/uitableview-as-inputview-for-uitextfield-didselectrowatindexpath-randomly-not-fi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!