【发布时间】: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