【发布时间】:2013-05-30 16:52:26
【问题描述】:
我的UIBarButtonItem 没有显示在我的UINavigationBar 中,需要帮助。
我正在尝试在我的第三个视图中添加UINavigationBar。由于我不太确定UINavigationController 是否有效,我决定手动初始化UINavigationBar 及其UINavigationItem initwithTitle。该代码有效,但我的问题是添加 UIBarButtonItem,因为它不会显示在 UINavigationBar 中。
- (void)viewDidLoad
{
[super viewDidLoad];
UINavigationBar *navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
UINavigationItem *navigationItem = [[UINavigationItem alloc] initWithTitle:@"Title"];
[navigationBar pushNavigationItem:navigationItem animated:NO];
UIBarButtonItem *button = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self
action:@selector(showPI:)];
self.navigationItem.rightBarButtonItem = button;
UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0.0, 44.0, self.view.frame.size.width, self.view.frame.size.height - navigationBar.frame.size.height) style:UITableViewStylePlain];
self.tableView = tableView;
[self.view addSubview:tableView];
[self.view addSubview:navigationBar];
[self showCurrencies];
self.tableView.dataSource = self;
self.tableView.delegate = self;
}
我不确定缺少什么。
【问题讨论】:
-
为什么您认为您的 nag 控制器不起作用?
-
我之前设法使用
UINavigationController更改了我的代码并崩溃了。所以我重做它并继续使用上面显示的方法。 -
您能否发布一些有关您的 nag 控制器和崩溃的详细信息?谢谢。
-
顺便说一下,只是为了澄清。您将在 AppDelegate 的
application: didFinishLaunchingWithOptions中初始化UINavigationController?
标签: ios uinavigationcontroller uinavigationbar uibarbuttonitem uinavigationitem