UITableViewCell内的IBAction未在iOS 9中调用 [英] IBAction inside UITableViewCell not called in iOS 9

查看:85
本文介绍了UITableViewCell内的IBAction未在iOS 9中调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义 UITableViewCell 子类,其中包含一些从笔尖连接的 IBAction 方法。

I have a custom UITableViewCell subclass which contains a few IBAction methods wired up from a nib.

在iOS 8下,一切都按预期工作。如果用户点击其中一个按钮,则会调用相应的 IBAction 。如果用户点击单元格上的任何其他位置,则会调用 UITableView didSelectRowAtIndexPath

Under iOS 8 everything works as expected. If the user taps one of the buttons, the appropriate IBAction is called. If the user taps anywhere else on the cell, the UITableView didSelectRowAtIndexPath is called.

在iOS 9下,我的IBAction永远不会调用方法。 UITableView didSelectRowAtIndexPath 总是被触发,无论用户点击单元格的位置(按钮与否)。

Under iOS 9, my IBAction methods are never called. The UITableView didSelectRowAtIndexPath is always fired regardless of where the user taps in the cell (button or not).

该项目是在Xcode 6 / Swift 1.2下编译的。

The project is compiled under Xcode 6 / Swift 1.2.

我在Apple论坛上发现这篇帖子没有解决方案。他们似乎有同样的问题。

I found this post on an Apple forum w/ no solution. They seem to have the same issue.

https://forums.developer.apple.com/thread/16179

推荐答案

我找到了解决方案,希望这个答案可以节省别人的时间。

I figured out the solution, hopefully this answer will save someone else the time.

我继承了这个代码库,但它有一些问题。在iOS 9下无效的 UITableViewCell的未使用 UITableViewCell nibs w / a ContentView 。相反,有人创建了一个 UIView nib,然后将其指向自定义 UITableViewCell 子类。这些笔尖没有 ContentView ,显然iOS 9对此更为挑剔。这个实现在iOS 8下工作正常,没有编译器或运行时错误或警告。

I inherited this code base and it had some issues. The UITableViewCell's that were not working under iOS 9 were not using UITableViewCell nibs w/ a ContentView. Instead, someone had created a UIView nib and then pointed it to a custom UITableViewCell subclass. The nibs did not have a ContentView and apparently iOS 9 is a little more picky about that. This implementation worked fine under iOS 8 and there were no compiler or runtime errors or warnings.

解决方案是创建一个新的 UITableViewCell 子类,让Xcode自动为它创建nib。然后我复制了旧笔尖的所有UI和代码,并将其粘贴到新笔尖的 ContentView 中。然后我不得不修复约束并重新连接到自定义子类的连接。

The solution was to create a new UITableViewCell subclass and let Xcode auto create the nib for it. Then I copied over all of the UI and code from the old nib and pasted it into the ContentView of the new nib. I then had to fix up the constraints and rewire the connections to the custom subclass.

这篇关于UITableViewCell内的IBAction未在iOS 9中调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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