1

I have a UIToolbar that sits at the bottom of the view. When the user is on an iPad, I want to add the toolbar to the right side of the navigation controller, because there will be room.

I added this code:

- (void)viewDidLoad{
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
            UIBarButtonItem *toolBarItem = [[UIBarButtonItem alloc]initWithCustomView:toolBar];
            self.navigationItem.rightBarButtonItem = toolBarItem;
        }
[super viewDidLoad];
    }

But the application crashes with the error:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Auto Layout still required after executing -layoutSubviews. UINavigationBar's implementation of -layoutSubviews needs to call super.'

I don't know why this is a problem, because I have seen this method used before. By the way, the toolbar items are added in interface builder rather than using an NSArray of buttons, could that make a difference?

Thanks!

Luke Baumann
  • 596
  • 12
  • 35

1 Answers1

0

A UIBarButtonItem is one of the controls that lives inside a toolbar. Are you sure of what you're doing? I can't follow what you're saying, but it seems like you are trying to add a toolbar inside a UIBarButtonItem. It's supposed to be the other way around, UIbarButtonItem lives inside the UIToolbar

Daddy
  • 9,045
  • 7
  • 69
  • 98
  • The UIToolbar contains several UIBarButtonItems, but I am trying to put the UIToolbar inside another UIBarButtonItem so that I can add it to the navigation bar. I didn't think there was an easier way. – Luke Baumann Jun 28 '12 at 17:45
  • The easier way is to create a custom UIView control that you can set the frame of arbitrarily. What you're trying to do is UIToolbar Inception! – Daddy Jun 28 '12 at 18:06