문제

How do I change the order of views displayed, when the two views I want to rearrange are not related?

I am trying to work on someone else's code, and they have a class which is a subclass of UITableViewController. I want to put a background in, so I put it as a subview of self.view .

The problem is, it's displayed in front of the table, and the table is located as self.tableView, not self.view.tableView . Since the two views aren't together, I can't use the sendSubviewToBack method.

self is the viewController class I'm working on.

Any ideas?

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];
도움이 되었습니까?

해결책

If you want to add subviews into your viewcontroller, you should use a subclass of UIViewController with manually added UITableView as subview and implementing the UITableViewDataSource and UITableViewDelegate protocols instead of using UITableViewController.

다른 팁

you can insert the background before the tabeview like this

[self.view insertSubview:background belowSubview:self.tableView.view];

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top