【问题标题】:Navigation Controller in presented view呈现视图中的导航控制器
【发布时间】:2014-05-11 16:52:54
【问题描述】:

我是 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. 所有视图都将包含导航控制器。

还有,这是稍后在“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:]: object cannot be nil'

【问题讨论】:

  • 所以现在你需要的是在关闭viewC之后,你需要回到viewA。?
  • 现在的问题是我什至无法实例化导航按钮,尽管我已经实例化了栏。它给出了类似“*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil”之类的错误,我不知道缺少什么。
  • 如果我编写一个示例,您将拥有 3 个屏幕,您将从 1-> 2 ->3 ->1 导航并且所有这些都将包含导航控制器,可以吗?
  • 当然,但我需要像更新我的问题一样实例化导航按钮。 (标准化)

标签: ios objective-c uinavigationcontroller


【解决方案1】:

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

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];
    }

【讨论】:

    【解决方案2】:

    这是在特定视图控制器上显示导航控制器的方式

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

    【讨论】:

    • 对不起,我的英语不好,但我需要用导航控制器将它定向到 LoginViewController。如果根据您的代码,它会将我带到完全黑屏的 SWRevealViewController(在我的情况下)。
    • 在“viewB”页面中实例化导航按钮时有帮助,但仍然出错。
    • 已更新。真的需要帮助>
    【解决方案3】:

    基本上现在的modelviewcontroller没有导航控制器,我们需要编写代码,请按照以下代码进行

    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 
    

    【讨论】:

    • 对不起,我的英语不好,但我需要用导航控制器将它定向到 LoginViewController。如果根据您的代码,它会将我带到完全黑屏的 SWRevealViewController(在我的情况下)。
    • 所以您只想回到之前的视图控制器?
    猜你喜欢
    • 2021-01-03
    • 1970-01-01
    • 1970-01-01
    • 2021-09-20
    • 2014-10-09
    • 2018-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多