【发布时间】: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 实例化时,我不知道该放什么。
任何帮助将不胜感激。提前致谢。
很抱歉给您带来了困惑。基本上我想做这样的事情:
- 我有一个主视图,我们将其命名为 viewA,它会调出一个 viewB。
- viewB 然后会变成 viewC。
- 最后,当我关闭 viewC 时,它会返回 viewA。
- 所有视图都将包含导航控制器。
还有,这是稍后在“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