简体   繁体   English

向导航栏添加按钮

[英]adding button to the navigation bar

i have a problem while adding button to the navigation bar.. My application consist of two view controllers added to the viewControllers array of a tabBarController. 我在向导航栏添加按钮时遇到问题。我的应用程序由两个添加到tabBarController的viewControllers数组的视图控制器组成。 Inturn this tabBarController is added to the viewControllers array of a navigationController. 反过来,这个tabBarController被添加到navigationController的viewControllers数组中。 In one of the views i have a textfield for entering dates . 在其中一种视图中,我有一个用于输入日期的文本字段。 On the tap of this textfield the datepicker will pop up. 点击此文本字段时,将弹出日期选择器。 simultaneously i want to display a done button on the navigation bar. 同时,我想在导航栏上显示完成的按钮。 how can i do this... i tried using 我该怎么做...我尝试使用

self.tabBarController.navigationController.navigationItem.rightBarButtonItem = self.doneButton;

But this is not working... 但这不起作用...

Pls help me out.. 请帮我..

Try this code, 试试这个代码,

UIBarButtonItem *addButton = [[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Done", @"")
                                                               style:UIBarButtonItemStyleBordered
                                                              target:self
                                                              action:@selector(DoneButton)] autorelease];

self.navigationItem.rightBarButtonItem = addButton;

Best of luck. 祝你好运。

Try with this 试试这个

UIBarButtonItem* _doneButton;
self.navigationItem.rightBarButtonItem = _doneButton;

use this one: 使用这个:

UIButton *myBtn = [[UIButton alloc]init];
[self.navigationItem.titleView addSubview:myBtn];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM