从超级视图iOS 7问题中获取UITableViewCell [英] Getting UITableViewCell from its superview iOS 7 issue

查看:125
本文介绍了从超级视图iOS 7问题中获取UITableViewCell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在单元格中有很少的UI对象有手势识别器实例。我需要获得按压对象所在的单元格。我有以下方法来获取它,但它只能在iOS 7之前工作:

I have few UI objects in the cell that have got gesture recognizer instance. I need to get cell where pressing object is located. I have the method below for getting it, but it just work before iOS 7:

UITableViewCell *cell = (UITableViewCell *)[[[sender view] superview]superview];

对于iOS 6,它返回 UITableViewCell

for iOS 6 it return UITableViewCell

对于iOS 7,它返回 UITableViewCellScrollView

for iOS 7 it return UITableViewCellScrollView

我认为新单元在iOS 7中有一些额外的视图,这就是为什么我像以前一样抓住 UITableViewCellScrollView 而不是 UITableViewCell

I think the new cell has some additional views in iOS 7, that's why I grab UITableViewCellScrollView instead of UITableViewCell as before.

推荐答案

正如您所看到的,依赖视图层次结构并不是一个好方法 - Apple可以随时打破它。

As you can see, relying on the view hierarchy is not a good approach - Apple can break it at any time.

您应该使用委托协议将您的单元格连接到控制器。

You should use a delegate protocol to connect your cell to the controller.

这篇关于从超级视图iOS 7问题中获取UITableViewCell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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