OK let me explain the scenario. I am developing an app which has a background image in the main window. I also have a navigation controller which does not sit at the top of the screen, but instead its 100px down. The navigation controller is translucent so you can see the background through it.
Now here’s the problem. At some point in the app, the user clicks a button, and I have a UITableViewController class which I add to the navigation controller using pushViewController. The problem with this, is that whilst the top of the tableview appears directly below the navigation controller, it has put a white background behind the navigation controller, taking away the translucent effect.
I have tried the following:
– Set the frame property of my tableviewcontroller’s view,
ie.
tableviewcontroller1.view.frame= CGRectMake(0,120,320,300);
(I have played around with the y position but it makes no difference no matter what I do.)
I thought maybe I could create a UIViewController and create a view with a transparent background, and then add the tableviewcontroller as a subview, and in doing so I was hoping that the frame bounds I set in the tableviewcontroller would take effect. I tried the following:
[parentview.view addSubView: tableviewcontroller1]; // runtime error
[parentview.view addSubView: tableviewcontroller1.view]; // runtime error
[parentview.view addSubView: tableviewcontroller.tableView]; // runtime error
I am really struggling to understand why setting the frame property of my tableviewcontroller.view has no effect, I have checked all my super views and none of them have the “resize subviews” property ticked.
I would very much appreciate some help on this, I’m really stuck here, I’ve done a lot of searching but cant find an answer.
Many thanks
Michael
What you call a navigation controller is perhaps a
UINavigationBar. The navigation controller controls the various view controllers, the nav bar is an UI interface belonging to the nav controller.To solve your problem, just give your table view a transparent background.
If for some reason you need a view that has some space above and below a table view controller, you have to create a view controller and insert a table view yourself. The standard
UITableViewControllerhas the table view set as the controllers’s mainviewand thus cannot be resized…UIViewControllersubclass (notUITableViewController).<UITableViewDelegate, UITableViewDatasource>@propertycalledtableView.selfas the table view’sdelegateanddatasource.viewof your view controller.