UITableView didSelectRowAt不称为iOS 10,但适用于9.3.5 [英] UITableView didSelectRowAt is not called iOS 10, but works for 9.3.5

查看:139
本文介绍了UITableView didSelectRowAt不称为iOS 10,但适用于9.3.5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于这个问题有很多问题,但到目前为止我找到的答案都不适用。在这种情况下,该表在iOS 9.3.5中正常工作,但不适用于iOS 10(或10.3.1)

There are lots of questions regarding this problem, but the answers I have found so far are not applicable. In this case, the table works correctly in iOS 9.3.5, but not for iOS 10 (or 10.3.1)

我已排除:


  • 未正确设置委托。委托执行3个功能, didSelectRowAt heightForRowAt editActionsForRowAt 后者是从右向左滑动,可以选择执行与选择行完全相同的功能。。这三个功能在v9.3.5上正常工作(通过模拟器测试,而旧的iPad我测试时使用。)当我通过模拟器或我的iPhone SE使用v10时, heightForRowAt ,和 editActionsForRowAt 工作但不是 didSelectRowAt (就此而言 - 我试过 willSelectRowAt 。它也不适用于v10。)

  • 任何印刷错误(因为它适用于9.3.5)

  • Not setting up the delegate properly. The delegate performs 3 functions, didSelectRowAt, heightForRowAt, and editActionsForRowAt. The latter is the right-to-left swipe which gives the option to perform the exact same functionality as selecting the row.. These three functions work correctly on v9.3.5 (as tested via simulator and and older iPad I test with.) When I use v10 via the simulator or my iPhone SE, the heightForRowAt, and editActionsForRowAt work but not the didSelectRowAt (and for that matter - I tried willSelectRowAt. It also did not work for v10.)
  • Any typographical error (because it works for 9.3.5)

我无法从iOS 9到iOS 10找到关于 tableView(:didSelectRowAt)的Swift更改。

I have not been able to find anything about a Swift change regarding tableView(:didSelectRowAt) from iOS 9 to iOS 10.

背景

我有一个带有相应xib的视图控制器(DetailVC )。这个xib有一个标签,然后是标签下面的tableview。表的单元格是另一个xib。

I have a view controller with a corresponding xib ("DetailVC"). This xib has a label then a tableview underneath the label. The table's cell is another xib.

视图控制器通过

let uomVC = DetailVC()
self.navigationController?.pushViewController(uomVC, animated: true)

然后在DetailVC中,我使用NSFetchedDataController并通过tableView数据源委托将其连接到tableview。 (核心数据加载并显示效果很好。)

Then within DetailVC, I use a NSFetchedDataController and connect it to tableview via the tableView Data Source delegate. (Core data loads and displays great.)

代码(我会根据需要/请求发布其他代码 - Swift 3)

Code (I'll post additional code as needed/ requested - Swift 3)

viewDidLoad() - partial

let nib: String = "DetailCell"
let reuseID: String = "detailCell"
tableView.register(UINib.init(nibName: nib, bundle: nil), forCellReuseIdentifier: reuseID)

tableView(:cellForRowAt)

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: reuseID) as! IngredientDetailCell
    cell.present(ingredient: _fetchedResultsController.object(at: indexPath))
    cell.isUserInteractionEnabled = true // Added later as a guess per SO suggestions
    return cell
}

为了论证,这不会打印

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {      
    print("Selected a row")
    // delegate?.selectedIngredient(_fetchedResultsController.object(at: indexPath))
    // self.navigationController?.popViewController(animated: true)
}

查看

推荐答案

为了完整,万一有人遇到这种奇怪的情况。

问题是我的UITableView细胞xib。我必须最初将它设计为UIView,然后添加UITableViewCell。层次结构应以UITableViewCell开头。我将UITableViewCell从视图下方移出(用红色圈出),删除视图并重新连接IBOutlets。它很适合iOS 9.3.5。

The problem was my UITableViewCell xib. I must have originally designed it as a UIView, then added the UITableViewCell. The hierarchy should begin with the UITableViewCell. I moved the UITableViewCell out from underneath the view (circled in red), deleted the view and re-connected the IBOutlets. It's just strange that it worked with iOS 9.3.5.

这篇关于UITableView didSelectRowAt不称为iOS 10,但适用于9.3.5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆