I've got a UITabBarController
which contains a UINavigationController
. Within the visible UIViewController
, I'm creating a UITableView
programatically as follows:
self.voucherTableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStylePlain];
self.voucherTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
However, the UITabBar is overlapping the UITableView
.
When I output the height of the [[UIScreen mainScreen] applicationFrame]
, it returns 460.00 whereas it should be 367.00.
In Interface Builder, I'm using the 'Simulated Metrics' which automatically sets the height of the view to 367.00.
Is there something I'm missing, no matter what I try I can't see to get the 367.00 height that I need.
As a temp fix, I've set the frame of the UITableView
manually, this isn't really ideal so it would be nice to work out why this isn't working:
self.voucherTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 367) style:UITableViewStylePlain];
You should add the
UINavigationController
instance to theUITabBarController
and then add a table view controller to therootViewController
property of theUINavigationController
instance which should make your life a lot easier.As a simple example of this, create an empty window-based application (the templates make this a lot more confusing than it really is).
Add your
UIViewController/UITableViewController
subclasses to the project then use this code as a guide to setting up your project. This code is in your AppDelegate class:In the code sample above the
BrowserViewController
is a subclass ofUIViewController
and theStoresViewController
class is a subclass ofUITableViewController
. TheUITabBarController
andUINavigationController
instances are created programmatically and added to the window.By subclassing the
UITableViewController
class you avoid having to create aUITableView
instance programmatically and get most everything you need out of the box.When you need to push a detail view onto the
UINavigationController
instance's stack, you just have use something similar to this:This will add the detail view
UIViewController
subclass to theUINavigationController
instance's view hierarchy for you and animate the transition.Lots of controllers in this, but it's totally worth it and will avoid a lot of the problems you're experiencing as this method allows the views to manage resizing and take toolbars/navigation bars into account all by themselves.
You should use self.view.bounds rather than [[UIScreen mainScreen] applicationFrame] as the last one returns you the whole screen frame while self.view.bounds provides you with your view bounds wich seems what you are searching for.