【发布时间】:2011-02-18 10:37:12
【问题描述】:
我将 UITableView 作为子视图添加到我正在处理的自定义 UIView 类中。但是我注意到,每当我滚动表格时,它都会调用我的类 layoutSubviews。我很确定它的表继承的 UIScrollview 实际上正在执行此操作,但想知道是否有办法禁用此功能,如果没有,为什么会发生这种情况?我不明白为什么当你滚动一个滚动视图时它需要它的超级视图来布局它的子视图。
代码:
@implementation CustomView
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
self.clipsToBounds = YES;
UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0.0, 15.0, 436.0, 132.0) style:UITableViewStylePlain];
tableView.dataSource = self;
tableView.delegate = self;
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
tableView.backgroundColor = [UIColor clearColor];
tableView.showsVerticalScrollIndicator = NO;
tableView.contentInset = UIEdgeInsetsMake(kRowHeight, 0.0, kRowHeight, 0.0);
tableView.tag = componentIndex;
[self addSubview:tableView];
[tableView release];
}
return self;
}
- (void)layoutSubviews {
// This is called everytime I scroll the tableview
}
@end
【问题讨论】:
-
但是告诉我你为什么这样做?你为什么要在自定义视图中添加表格视图?
-
长话短说,我正在创建一个自定义 PickerView,它允许多项选择,并且大小与标准不同。它基本上显示了一个 PickerView 背景,上面有一个清晰的表格
-
你看过这个吗?这家伙似乎有相反的问题,因为没有调用 layoutSubviews。他还提到了一个修复,如果你把它倒过来,可能对你有用。 :) stackoverflow.com/questions/728372/…
-
这种行为在 iOS 5 及更高版本中发生了变化 -- stackoverflow.com/questions/8036457/…
标签: iphone uitableview uiview uiscrollview