UITableView 作为 UITextField 的 inputView didSelectRowAtIndexPath 随机未触发 [英] UITableView as inputView for UITextField didSelectRowAtIndexPath randomly not fired
问题描述
我有一个 UITableViewController,我用它来覆盖 UITextField 子类的 inputView.有时 tableView didSelectRowAtIndexPath 会停止触发,直到用户滚动表格并尝试再次单击.我似乎无法解决导致细胞无反应的原因.大多数情况下它工作得很好,但随机单元格停止响应触摸,直到用户稍微滚动 tableview.
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.
据我所知,我在视图中没有任何 TapGestureRecognizers,并且在 UITableViewCell 中尝试覆盖 HitTest,但似乎无法弄清楚问题.
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?
这是 tableView 控制器代码:
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!
}
}
推荐答案
我遇到了同样的问题.在我的表格视图中,它没有在第一次点击时点击表格的最后一行.它突出显示了它,但没有调用 didSelectRowAtIndexPath.所有其他行工作正常.但是如果我打开 tableview 反弹,那么它似乎解决了问题
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
还可以尝试在 Interface Builder 中删除 Show Selection on Touch,如下所示:
Also try removing Show Selection on Touch in Interface Builder as follows:
希望能帮到你
这篇关于UITableView 作为 UITextField 的 inputView didSelectRowAtIndexPath 随机未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!