mar*_*ram 12 iphone uitableview uiscrollview uiview
我将UITableView作为子视图添加到我正在处理的自定义UIView类中.但是我注意到每当我滚动表时它都会调用我的类layoutSubviews.我很确定UIScrollview表是继承的,实际上是在做这个,但想知道是否有办法禁用这个功能,如果不是为什么会发生?我不明白为什么当你滚动一个scrollview时,它需要超级视图来布局它的子视图.
码:
@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
Run Code Online (Sandbox Code Playgroud)
是的,UIScrollView 每当滚动时都会调用layoutsubviews。我可以发誓这在文档中的某个地方有说明,但我想没有。
不管怎样,普遍的想法是 UIScrollView 应该布局它的东西,这样当前看不到的视图就不应该被布局。当用户在滚动视图中滚动时,它应该根据需要添加和删除子视图。我猜这就是 TableView 用于将隐藏的表格单元格排队的方法。
您是否有任何理由关心layoutsubviews是否被调用?
归档时间: |
|
查看次数: |
5315 次 |
最近记录: |