导航控制器在呈现视图中

时间:2014-04-01 04:46:51

标签: ios objective-c uinavigationcontroller

我是IOS编程的新手。我想问一下如何在呈现的视图中实例化导航控制器。这是我从上一个视图中实例化导航栏的方法。

SWRevealViewController *revealController = self.revealViewController;

    UINavigationController *frontNavigationController = (id) revealController.frontViewController;

    if ( ! [frontNavigationController.topViewController isKindOfClass:[CalibrateViewController class]]) {
        CalibrateViewController *promotionViewController = [[CalibrateViewController alloc] init];
        UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:promotionViewController];
        [revealController setFrontViewController:navigationController animated:YES];
    }
    else {
        [revealController revealToggle:self];
    }

但是当我想用现在的观点做的时候,

LoginViewController *promotionViewController = [[LoginViewController alloc] init];
[self presentViewController:promotionViewController animated:YES completion:nil];

当我想使用presentView进行实例化时,我不知道该放什么。

任何帮助将不胜感激。提前谢谢。

很抱歉这个混乱。基本上我想做这样的事情:

  1. 我有一个主视图,让我们将它命名为viewA,它将调出一个viewB。
  2. viewB然后将变为viewC。
  3. 最后,当我解除我的viewC时,它将返回viewA。
  4. 所有视图中都会有导航控制器。
  5. 你好,这是稍后在" viewB"," viewC"上创建的导航按钮。

    SWRevealViewController *revealController = [self revealViewController];
    
    [revealController panGestureRecognizer];
    [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
    
    UIBarButtonItem *revealButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"reveal-icon.png"] style:UIBarButtonItemStyleBordered target:revealController action:@selector(revealToggle:)];
    
    
    self.navigationItem.leftBarButtonItem = revealButtonItem;
    
    
    //check if whether to use barTintColor instead of tintColor. (IOS difference)
    if (IS_OS_7_OR_LATER) {
        // here you go with iOS 7
        self.navigationController.navigationBar.barTintColor = UIColorFromRGB(0x808080);
    }
    else
    {
        self.navigationController.navigationBar.tintColor = UIColorFromRGB(0x808080);
    }
    
    self.navigationController.navigationBar.translucent = YES;
    //=======================================================================================
    

    它在实例化导航按钮的视图上给出错误。 错误如下所示: *由于未捕获的异常终止应用' NSInvalidArgumentException',原因:' * - [__ NSArrayM insertObject:atIndex:]:对象不能为零

4 个答案:

答案 0 :(得分:0)

这是您在特定视图控制器上呈现navigationcontroller的方法

LoginViewController *promotionViewController = [[LoginViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc]init];
[navigationController pushViewController:promotionViewController animated:YES];
[self presentViewController:navigationController animated:YES completion:nil];

答案 1 :(得分:0)

查看此链接可能对您有用Click Here

答案 2 :(得分:0)

尝试使用以下代码代替您的代码:

UINavigationController * frontNavigationController =(id)revealController.frontViewController;

  if ( ! [frontNavigationController.topViewController isKindOfClass:[CalibrateViewController class]]) {
        CalibrateViewController *promotionViewController = [[CalibrateViewController alloc] init];
        UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:promotionViewController];
        [self.navigationController pushViewController:navigationController animated:YES];
    }
    else {
        [revealController revealToggle:self];
    }

答案 3 :(得分:0)

基本上,Presentmodelviewcontroller没有我们需要编码的导航控制器,请按照下面的代码

NextViewController *ivc= [[NextViewController alloc]init]; // here you are allocation your next viewController
UINavigationController *naviCtrl =[[UINavigationController alloc]initWithRootViewController: ivc]; // here you are allocation navigation controller for your next viewController
[self presentViewController:naviCtrl animated:YES completion:nil];   // here you are presenting your next view controller