开发者

Making a dynamic NavigationBar

I want a UINavigationBar whose contents change in response to other events in the app. Most immediately, I'd like to have the buttons on the bar loaded dynamically in response to other vari开发者_运维问答ables in the program. But in the more general case I'd like to be able to change the contents of the UINavigationBar on the fly, while the program is running.

The hurdle I'm running into is that the UINavigationBar loads its contents when its first displayed and there doesn't seem to be a method to make it alter them after that. What's the best workaround?


This is fairly easy to do. The best way is to pre-load all of the options for the different objects you want in your navBar so that you need only switch them in and out based on the user's input, but you can load them on the fly. When the user does an action which you want to change the navBar, simply add:

self.navigationItem.rightBarButtonItem = nil;
UIBarButtonItem * newButton = [[UIBarButtonItem alloc] initWithTitle:@"What you want to call it" style:UIBarButtonItemStyleBordered target:self action:@selector(whatYouWantTheButtonToCall)];
self.navigationItem.rightBarButtonItem = newButton;
[newButton release];

For other options then a button, you can look here. Hope that helps!


OK, I found one way: After editing a navigation bar item, you can call [self loadView] ...to prompt a reload.

That works, but it's a bit blech.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜