【发布时间】:2014-08-26 15:50:36
【问题描述】:
我已使用此代码从我的UITableViewCell 中获取UIButton,但它不起作用。所以我调试了半个小时才知道它在哪个superview中。
UIButton *button = (UIButton *)sender;
UITableViewCell* cell = (UITableViewCell*)button.superview.superview.superview;
UITableView* tableView = (UITableView*) cell.superview.superview;
NSIndexPath* indexPath = [tableView indexPathForCell:cell];
我现在的问题是:我如何知道将来 UITableView 或其他的层次结构是什么?没有一个列表可以让我看到我需要多少超级视图不对其进行 100 次测试并设置 BreakPoints 以查看它指的是什么类?
问候
【问题讨论】:
-
在你的代码中添加一个断点...当它暂停时,试试
po [UIWindow recursiveDescription];你可以用几乎任何有效的 UIView 替换 UIWindow。不过,我会谨慎使用这种方法,因为@architectpianist 正确地提到了它的问题。 -
我谦虚地建议我在标记副本中的解决方案作为解决此问题的最佳方法。
标签: ios objective-c