将后退按钮放在由另一个模态视图推动的模态视图内

时间:2011-01-25 15:38:37

标签: iphone objective-c modalviewcontroller

检查这个,即时推动另一个模态视图内的模态视图。但是,我试图在这个模态视图中放置一个按钮,但没有运气。

我做错了什么?

谢谢!

 CadastroViewController *addController = [[CadastroViewController alloc] initWithNibName:@"CadastroViewController" bundle:nil];

// This is where you wrap the view up nicely in a navigation controller
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addController];

// You can even set the style of stuff before you show it
navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;

navigationController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"OK" style:UIBarButtonItemStyleBordered target:self action:@selector(buy)];


// And now you want to present the view in a modal fashion all nice and animated
[self presentModalViewController:navigationController animated:YES];

// make sure you release your stuff
[navigationController release];
[addController release];

3 个答案:

答案 0 :(得分:3)

您必须将新导航项添加到实际viewcontroller的导航栏中 - 而不是导航控制器。

addController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"OK" style:UIBarButtonItemStyleBordered target:self action:@selector(buy)];

答案 1 :(得分:1)

您应该在按钮中添加按钮  -(void) viewDidLoad控制器类的CadastroViewController

这将是这样的:

- (void) viewDidLoad
{
    [super viewDidLoad];
    UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithTitle:@"OK" style:UIBarButtonItemStyleBordered target:self action:@selector(buy)];
    self.navigationController. leftBarButtonItem = button;
    [button release];
}

[self presentModalViewController: navigationController animated:YES];在您的示例中是正常的,只是您应该在viewDidLoad中执行的所有其他初始化

答案 2 :(得分:0)

在我看来,问题出在这里:

  [self presentModalViewController: navigationController animated:YES];

而是尝试这样做:

  [self presentModalViewController: addController animated:YES];