开发者

How to add bar buttons to UINavigation bar

Hey, I am try开发者_如何学Pythoning to add bar button items to my UINavigationBar (nav bar) but I have found out that bar button items are not properties of navigation bar and hence can't be accessed directly like:

UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" 

    style:UIBarButtonSystemItemDone target:nil action:nil];

    navBar.rightBarButtonItem =rightButton;

I am creating my navigation bar programmatically.

Apparently, there is something called UINavigation Item that has to be dealt with to add bar buttons. Can anyone tell me how to go about this? How to create this UINavigation item programmatically and add this to my navBar and then add the bar buttons to it.


UINavigationBars shouldn't be used on their own, outside of a UINavigationController.

When a navigation controller is used, each view controller on the navigation stack has a UINavigationItem. It is this UINavigationItem that you can add bar button items to.

self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Done"
                                                                           style:UIBarButtonSystemItemDone
                                                                          target:nil action:nil] autorelease];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜