如何向uinavigationcontroller添加右键

时间:2012-10-18 20:47:22

标签: objective-c ios ipad uinavigationcontroller uinavigationitem

如何向添加到UINavigationControl的{​​{1}}添加按钮? (该项目不是基于ViewController。)

以下是我添加到UINavigationControler方法的代码:

viewDidLoad

有人可以帮我解决第7-9行吗?

2 个答案:

答案 0 :(得分:1)

UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"Button" 
    style:UIBarButtonSystemItemDone target:nil action:nil];
UINavigationItem *item = [[UINavigationItem alloc] initWithTitle:@"Awesome"];
item.rightBarButtonItem = rightButton;
item.hidesBackButton = YES;
[navigationBar pushNavigationItem:item animated:NO];

答案 1 :(得分:0)

您需要UINavigationController吗?为什么不使用简单的UINavigationBar。以下是一些示例代码:

UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:
                              CGRectMake(0,0,self.view.frame.size.width, 49.0f)];
[self.view addSubview:navBar];
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:@"Cancel"
      style:UIBarButtonItemStylePlain target:self action:@selector(cancel)];
UINavigationItem *rightBarButtonItem = [[UINavigationItem alloc] init];

[rightBarButtonItem setRightBarButtonItem:cancelButton];

[navBar pushNavigationItem:rightBarButtonItem animated:NO];