开发者

How to create navigation bar item in the custom Navigation Bar in iPhone?

I have created one custom view and added a web view as subview of that custom view. And i have created one navigation bar in programmatically. Now i want to create one Left or Right navigation bar buttons in that view.

navigBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];

navigBar.tintColor = [UIColor blackColor];

[self.view addSubview:navigBar];

UIBarButtonItem *homeButton = [[UIBarButtonItem alloc] initWithTitle:@"Home" style:UIBarButtonSystemItemAction target:self action:@selector(homeButtonAction)];

navigBar.rightBarButtonItem = homeButton; // it's not supports

How can i create navigation bar item in the custom navigation bar?, i want to remove the custom view. So please Help m开发者_如何学编程e out!

Thanks.


On your navigationbar reference you could invoke the two methods:

- (void)pushNavigationItem:(UINavigationItem *)item animated:(BOOL)animated
- (UINavigationItem *)popNavigationItemAnimated:(BOOL)animated

In your custom view controller class write something like this:

self.navigationItem.leftBarButtonItem = yourButton;
self.navigationItem.rightBarButtonItem = yourSecondButton;

So you could write something like this:

[myNavBarReference pushNavigationItem:self.navigationItem animated:NO];


rightBarButton is defined for UINavigationItem. See the documentation for the UINavigationItem and for the UINavigationBar (Specially Adding Content to a Navigation Bar).

The method to use is - (void)pushNavigationItem:(UINavigationItem *)item animated:(BOOL)animated


See http://developer.apple.com/library/ios/documentation/uikit/reference/UINavigationItem_Class/Reference/UINavigationItem.html

You would invoke methods to self.navigationItem.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜