使用presentModalViewController时的问题

时间:2013-05-19 03:57:09

标签: iphone view

在我的应用程序中,我尝试使用该功能     [self.navigationCotroller presentModalViewController:nextVC animated:YES]; 然而,当它进入下一个视图时,子视图实现了整个屏幕(当然它确实如此) 问题是,我怎么能添加引导视图的条形按钮?

我试过用

  1. self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"back" style:UIBarButtonItemStyleDone target:self action:@selector(Go)];
    

    在函数viewdidLoad中,但它没有工作,没有条形甚至按钮显示

  2. UINavigationBar *bb =  [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 44)];
    self.NVBar = bb;
    [self.view addSubview:bb];
    
  3. 但是,我不知道如何在新的navigationBar --- NVBar

    中添加一个按钮

    您想给我一个解决方案吗?

2 个答案:

答案 0 :(得分:0)

您需要弹出新的视图控制器才能自动包含导航栏。

在视图控制器中,您的代码来自,

//*** Hook up four buttons to these actions and play around with it for a 
//*** better sense of what is going on.    
//*** JSBViewController is the name of my test class
//*** You should use your ViewController class that you are currently coding so
//*** you can see the difference of pop/push versus present/dismiss inside of a            
//*** navigation controller
-(IBAction)push:(id)sender
{
  JSBViewController * viewController = [self.storyboard instantiateViewControllerWithIdentifier:NSStringFromClass([JSBViewController class])];
  [self.navigationController pushViewController:viewController animated:YES];
}
-(IBAction)pop:(id)sender
{
  [self.navigationController popViewControllerAnimated:YES];

}
-(IBAction)present:(id)sender
{
  JSBViewController * viewController = [self.storyboard instantiateViewControllerWithIdentifier:NSStringFromClass([JSBViewController class])];
  [self presentViewController:viewController animated:YES completion:nil];
}
-(IBAction)dismiss:(id)sender
{
  [self dismissViewControllerAnimated:YES completion:nil];
}

对于您正在寻找的行为,您需要使用推送方法
[self.navigationController pushViewController:viewController animated:YES];

答案 1 :(得分:0)

如果使用[self.navigationController pushViewController:picker animated:YES];推送nextVC,则导航栏应保持在顶部。然后你可以用`[self.navigationController popViewControllerAnimated:YES]回弹;

使用导航栏从模态视图返回是非常不寻常的。 `