[英]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. 我创建了一个自定义视图,并添加了一个Web视图作为该自定义视图的子视图。 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 me 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];
See http://developer.apple.com/library/ios/documentation/uikit/reference/UINavigationItem_Class/Reference/UINavigationItem.html 请参阅http://developer.apple.com/library/ios/documentation/uikit/reference/UINavigationItem_Class/Reference/UINavigationItem.html
You would invoke methods to self.navigationItem. 您将调用self.navigationItem的方法。
rightBarButton
is defined for UINavigationItem
. rightBarButton
是为UINavigationItem
定义的。 See the documentation for the UINavigationItem
and for the UINavigationBar
(Specially Adding Content to a Navigation Bar ). 请参阅
UINavigationItem
和UINavigationBar
(特别向导航栏添加内容 )的文档。
The method to use is - (void)pushNavigationItem:(UINavigationItem *)item animated:(BOOL)animated
使用的方法是
- (void)pushNavigationItem:(UINavigationItem *)item animated:(BOOL)animated
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.