0

I'm puzzed. The UIToolbar in my iPhone-only app behaves differently when run on an iPad. On the iPhone I get the desired result (UIToolbar is visible), the same app run on the iPad doesn't show the UIToolbar at all.

I assume I'd doing something wrong, but I can't imagine how the same app would behave differently -- same version of iOS 7.0.3 -- iPhone vs iPad.

I dragged on a UIToolbar to my Storyboard and added UIBarButtonItems to it. I connected these as IBOutlets to the view controller header file. I do this:

NSArray *items = @[self.buttonBarItemShare, self.buttonBarItemFlexibleFirst, self.buttonBarItemDuplicate];
[self.bottomToolbar setItems:items]; // works on iPhone, no toolbar on iPad

On the iPhone I see it, on the iPad I don't.

I also tried to do this:

NSArray *items = @[self.buttonBarItemShare, self.buttonBarItemFlexibleFirst, self.buttonBarItemDuplicate];
[self setToolbarItems:items]; // visible on iPhone, nothing on iPad

With the result that when run on the iPhone the toolbar and all the buttons as they appear on the Storyboard are visible -- which are not the ones in the items array above and I can't get at the buttons via the IBOutlets. And when run on the iPad there is no toolbar at all.

I can understand (and expect) that I am doing something wrong, but why is the behavior different depending on the device?

UPDATE:

@Aaron Brager pointed me directly how to debug this. It was a constraint error.

ToddB
  • 2,490
  • 3
  • 23
  • 40
  • Where do you initialize `self.bottomToolbar`? Can you set a breakpoint there? Does it get initialized on iPad? – Aaron Brager Nov 15 '13 at 16:24
  • Aha, I wasn't specifically initializing self.bottomToolbar, I thought the Storyboard and IBOutlet took care of that. A quick check shows indeed there is an instance of it. I added a line to explicitly init it as well -- `[[UIToolbar alloc] init]` with no change. (The button items also I don't specifically instantiate, as IBOutlets I didn't think I needed to). – ToddB Nov 15 '13 at 16:40
  • If you have a connected IBOutlet, that will initialize it (you don't need to do it programmatically). – Aaron Brager Nov 15 '13 at 18:28
  • I created a sample iPhone-only project using your provided code and issue description. The UIToolbar appeared fine in the iPad simulator. Whatever the issue is, it's not in what you've posted. I would start by setting a breakpoint on `[self.bottomToolbar setItems:items];`, and look at everything in the console to see if things are as you expect. You can start with `po self.bottomToolbar` to make sure it's instantiated, and `po [[self view] recursiveDescription]` to see your current view heirarchy. (Maybe your toolbar will be there, but will be hidden or have an `alpha` of `0`.) – Aaron Brager Nov 15 '13 at 18:40
  • Aaron, that was outrageously helpful. :-). I didn't know you could do `po [[self view] recursiveDescription]`. I can see the problem, the toolbar is there but it's off the bottom of the screen. The same for the UITableView, it extends off the bottom of the screen which wasn't noticeable. I don't yet see the root cause but it must be a constraint somewhere. Thank you! (I'll update the question when I figure it out, hopefully shortly). – ToddB Nov 15 '13 at 19:43
  • Got it. Constraint issue. I cannot thank you enough! – ToddB Nov 15 '13 at 19:54

0 Answers0