Question

I have a navigation based application which I'm trying to add a unique UIToolbar that will be persistent no matter which is the current view, using this:

Persistent UIBarButtonItem in UIToolbar?

The problem is my when I set the frame for the navigationController, the UITableView inside the navigationController shifts 20px under the navigation bar, as if it started drawing behind the status bar.

Any ideas on how I can fix this? I'm stuck!

Was it helpful?

Solution

I ended up using the built-in toolbar of the navigationController.

So on every viewDidLoad I set the current toolbarItems to the same array:

- (void)viewDidLoad {
    [super viewDidLoad];

    MyDelegate *appDelegate = (MyDelegate *)[[UIApplication sharedApplication] delegate];
    [self setToolbarItems:[appDelegate toolbarItems] animated:YES];
}

I don't see any transitions and I could always set it to different buttons if I need to on a specialy viewController.

Maybe this is the way it's supposed to be done. Occam's razor, anyone? :)

OTHER TIPS

I've had this happen a lot when adding sub views to the UIWindow. I tried all sorts of advice from people but eventually just did shifted the frame origin down 20px to accommodate the status bar.

I've made a custom object deriving from UIToolbar, and added a property called staticItems that I populate in the init method with 3 UIBarButtonItem (and their logic)

I've set "Show Toolbar" to my UINavigationController object, and changed toolbar's class to my new one.

Then I've set navigation's parent object as navigation's delegate, and implemented these method

- (void)navigationController:(UINavigationController *)navigationController  willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    [viewController setToolbarItems:downloadToolbar.staticItems animated:NO];
}
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{}

Really close to what you've done, a bit more easy to maintain. Hope will help somebody else.

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