iOS9-UITableViewCellContentView隐藏了Cell内的控件 [英] iOS9 - UITableViewCellContentView is covering up Controls inside Cell

查看:290
本文介绍了iOS9-UITableViewCellContentView隐藏了Cell内的控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个带有开关的自定义UITableViewCell,称为"SwitchCell". 仅在iOS9中,使用Xcode 7 beta,单元格中的内容"视图位于开关的顶部. (请参见视图层次结构"的屏幕截图.您可以清楚地看到该单元的内容视图位于其他视图之上.):

I have made a custom UITableViewCell called "SwitchCell" that has a switch. In iOS9 Only, using Xcode 7 beta, the Content view in the cell is on top of the switch. (See screenshot of View Hierarchy. You can clearly see that the content view of the cell is on top of the other views. ):

因此,所有对UISwitch的触摸都将被拦截,并且IBAction不会触发. 在iOS8中,这不是问题.请参阅iOS 8.4模拟器的屏幕截图.您可以看到控件顶部没有内容视图:

So all the touches to the UISwitch are intercepted, and the IBAction does not fire. In iOS8, this is not a problem. See screenshot for iOS 8.4 simulator. You can see that there is no content view on top of the controls:

有人遇到过这个问题吗? 我尝试从头开始重新构建NIB,但结果还是一样.

Has anyone had this problem? I tried remaking the NIB from scratch, but the same result occurs.

我的NIB是自由格式的尺寸视图,没有状态栏.它有两个出口:一个用于UILabel,一个用于UISwitch.

My NIB is a freeform size view with No status bar. It has two outlets: one for UILabel, one for UISwitch.

请确保检查下面的答案,以确认该单元格的根视图不仅是UIView,而且是UITableViewCell.这个问题也可能是它的副作用.

please make sure to check the answer below that asks to verify that the cell's root view is not just a UIView but a UITableViewCell. This issue may also be a side effect of this.

推荐答案

经过更多调查和搜索,我在这里找到了解决方案: UITableViewCell中的按钮在ios 7下未响应

After more investigation and searching, i found my solution here: Button in UITableViewCell not responding under ios 7

对我来说固定的是: cell.contentView.userInteractionEnabled =否;

What fixed it for me was: cell.contentView.userInteractionEnabled = NO;

这可以防止单元格内容视图接管触摸事件,即使它位于其他视图之上.

This prevents the cell content view from taking over the touch events, even though it's on top of the other views.

此问题不仅在iOS9上发生,而且在iOS7上也发生.在iOS8中,内容"视图位于控件的后面.

This issue was not only happening on iOS9, but on iOS7 as well. In iOS8, the Content view was behind the controls.

这篇关于iOS9-UITableViewCellContentView隐藏了Cell内的控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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