当我想重新排列的两个视图无关时,如何更改显示的视图顺序?
我正在尝试处理别人的代码,他们有一个类,它是UITableViewController的子类。我想把背景放进去,所以我把它作为self.view的子视图。
问题是,它显示在表的前面,而表位于self.tableView,而不是self.view.tableView。由于两个视图不在一起,我不能使用sendSubviewToBack方法。
self是我正在研究的viewController类。
有什么想法吗?
UIImageView *background = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"editInfoBG.png"]];
background.frame = CGRectMake(0, 0, 320, 416);
[self.view addSubview:background];
// Doesn't work, the table is not a subview of self.view
[self.view sendSubviewToBack:background];
答案 0 :(得分:1)
如果要将子视图添加到viewcontroller中,则应使用UIViewController
的子类,并手动添加UITableView
作为子视图,并实现UITableViewDataSource
和UITableViewDelegate
协议使用UITableViewController
。
答案 1 :(得分:0)
你可以像这样在tabeview之前插入背景
[self.view insertSubview:background belowSubview:self.tableView.view];