我想在UIView
类中的表视图上方和NavigationBar下添加一个tableViewController
。如果我这样添加它:
[self.view addSubview:self.manualView];
它位于UITableView上方(实际上,我希望它们位于相同的z-index上)。我还想在用户按下某个按钮时以编程方式删除UIView。
最佳答案
有两种方法可以解决此问题。
天真(创建视图并将其添加到子视图):
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
view.backgroundColor = [UIColor blackColor];
[self.view addSubview:view];
这引入了与布局放置和空间冲突有关的许多问题。
更好的解决方案:
通过以下方式返回表的相应部分的页眉视图或页脚视图:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
此方法是UITableViewController默认遵循的UITableViewDelegate协议的一部分。