0

如何将按钮UINavigationControl添加到我添加到的 a 中ViewController?(该项目不是UINavigationControler基于。)

这是我添加到我的viewDidLoad方法中的代码:

navigation = [[UINavigationController alloc] init];
navigation.view.frame = CGRectMake(0, 0, 1024, 748);
navigation.navigationBar.tintColor = [UIColor blackColor];
navigation.navigationBar.alpha = 1.0f;
navigation.navigationBar.translucent = NO;

UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStylePlain target:self action:@selector(cancel)];          
[navigation.navigationItem setRightBarButtonItem:cancelButton animated:YES];
[cancelButton release];

[self.view addSubview:navigation.view];

[self pushPresentationList];

有人可以帮我修复第 7-9 行吗?

4

2 回答 2

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];
于 2012-10-18T20:52:54.537 回答
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];
于 2012-10-19T03:55:33.820 回答