当视图中的按钮被触发UIViewController
时,我正在尝试将子视图添加到视图中。UITableViewCell
我面临的问题是从表格视图单元格的子类中调用父视图。
问问题
151 次
3 回答
1
tableView
您可以在视图层次结构中查找父级:
-(UITableView*) parentTableView
{
UIView* v = [self superview];
while (v && ![v isKindOfClass:[UITableView class]]) {
v = [v superview];
}
return v;
}
于 2012-08-12T20:18:39.173 回答
0
创建 tableviewcell 子类时,通过创建自己的 init 方法将指针传递给 parentview 的实例。然后将该指针保存在您的子类中作为实例变量。这样,当子类中发生某些事情时,您可以对父级做任何您想做的事情。如果您需要更多帮助,请告诉我。
于 2012-08-12T19:50:04.797 回答
0
我建议UIViewController
为UITableViewCells
. 您必须创建一个协议并UIViewController
实施它。此外,您需要子类UITableViewCell
化才能添加委托属性。
#import <Foundation/Foundation.h>
@protocol YourTableViewCellDelegate
- (void)didTouchButton:(UIButton *)theButton;
@end
在UIButton
检查委托是否存在的操作方法中:
if (self.delegate != nil && [self.delegate respondsToSelector:@selector(didTouchButton:)]) {
[self.delegate performSelector:@selector(didTouchButton:) withObject:_theButton];
}
于 2012-08-12T20:35:53.060 回答