Question

I'm working on an iPhone app with iOS 5.1 using Storyboards. I have a UIViewController with a UITabBar component at the bottom. I'm using the UITabBar delegate event didSelectItem to load in different view controllers to use for each tab page using insertSubview for example :

[[self view] insertSubview:[salesQuotesVC view] belowSubview:mainTabBar];

The view controller I'm inserting into the host view contains a UITableView control with all autosizing anchors/constraints enabled so it should stretch to the available space. It also has simulated metrics Top Bar=Navigation Bar and Bottom Bar=Tab Bar. Everything works fine except for the resizing of the UITableView when switching between 3.5" and 4" (iPhone 5) screens. If I set Interface Builder to 3.5" form factor then it runs fine on a 3.5" device, but the table is too short on a 4" device. Likewise if I set the IB form factor to 4" it runs fine on a 4" device but the table is too long and runs underneath the tab bar on a 3.5" device.

I've never had problems with autoresizing between 3.5"/4" devices before, but so far I've only ever used UITabViewControllers for tab pages. This is the first time I've coded the tab switching myself using a UITabBar and UIViewController (I'm doing it for reusability purposes). I'm guessing the resize issues are to do with the insertSubview ?

Was it helpful?

Solution

You haven't had problems before because the view controller has done it for you. If you're adding the view as a subview then you need to do it yourself. Simply set the frame of the table view before you add it as a subview and then your autoresizing rules will take care of any subsequent changes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top