views:

530

answers:

3

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:

http://stackoverflow.com/questions/1072080/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!

A: 

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.

pzearfoss
I tried that, but the navigationBar shifts along the tableView, so I end up with a 20px blank white bar above everything. And the tableView is still hidden.
leolobato
Can you post a link to a screengrab of the app running, that might help me see better what's going on.
pzearfoss
+1  A: 

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? :)

leolobato
leolobato you saved me some scratching my head time with your question/answer. Just a small thing I've noticed about this implementation: If you look really closely at your UIToolbar when you move between UIViewControllers, it actually does fade the toolbar items in and out again. I'm going to run with this kind of solution for now, with an eye out for the ideal solution in an independent UIToolbar (outside the UINavigationController).
Jessedc
A: 

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.

sosergio