取决于您如何创建视图层次 - 将其插入任一表视图或波纹导航栏上面:
- (void)viewDidLoad
[super viewDidLoad];
// let's assume self.tableView is table view
// and self.navigationBar is navigation bar
// that both are subviews of [self view]
UIView *customSubview = [[UIView alloc] initWithFrame:someRect];
[[self view] insertSubview:customSubview aboveSubview:[self tableView]];
// -- OR --
[[self view] insertSubview:customSubview belowSubview:[self navigationBar]];
}
还有在特定索引中插入您的子视图的选项。所以,如果您的导航栏最上面的(即索引0)和表视图是最底部(即[[[[self view] subviews] count] - 1]
指数)可以插入这样之间,您的自定义视图:
[[self view] insertSubview:customSubview atIndex:1];
这样,你的表视图将下降通过在它的父和一个水平的子视图的“分层”将以下:
- 索引0 - 导航栏
- 索引1 - 自定义子视图
- 索引2 - 表视图
虽然把自定义的子视图放到标准的超级视图中,但是你必须保持自己的位置,因为它不会像以前那样一起滚动tableview。
在我的例子中,self.view == self.tableview,因为“self”是一个UITableViewController。 –
完成! [self.tableView.superview insertSubview:customView aboveSubview:self.tableView]就是我想要的!谢谢〜 –