- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
这是我的层次结构:
A - B - C - D (tabs)
| | | |
| | | |
----------------> AddEventViewController (can be called from any tabs)
|
|
|----> SuggestFeedController (can be accessed from B only)
假设我目前在 D 选项卡中,我调用了 AddEventViewController。在此之后,我想将用户重定向到“SuggestFeedController”,但我想保留层次结构,这意味着按下后退按钮应该重定向到 B 而不是 AddEventViewController 或 D。
我尝试做的是以下内容:
UITabBarController *tabbarController = ((UITabBarController *)appDelegate.window.rootViewController);
[tabbarController setSelectedIndex:1]; // Selecting the B tab
UIStoryboard* storyboard= appDelegate.window.rootViewController.storyboard;
UICategoryFeedController *cfvC = [storyboard instantiateViewControllerWithIdentifier:@"UICategoryFeedController"]; // Instantiating B view Controller
SuggestFeed *suggestFeed = [storyboard instantiateViewControllerWithIdentifier:@"SuggestFeed"];
NSArray *viewControllers = [[NSArray alloc] initWithObjects:cfvC, suggestFeed, nil]; // Trying to create my own navigation stack, B first, then Suggest Feed
[self.navigationController pushViewController:suggestFeed animated:NO]; // Some guys on internet do the push, even if I don't think it's necessary because it's already in the stack
NSLog(@"nav stack1 : %@", self.navigationController.viewControllers );
/* returns stack1 : (
"<D: 0xa627990>",
"<AddEventViewController: 0x108cb7e0>",
"<SuggestFeed: 0x123735f0>"
) */
[self.navigationController setViewControllers:viewControllers animated:NO];
NSLog(@"nav stack2 : %@", self.navigationController.viewControllers );
/* returns stack2 : (null) */
我做错了吗? (愚蠢的问题)
为什么 stack2 为零,而我已经从数组中设置了 viewControllers?
如果你能带来一些帮助,在此先感谢:-)
最佳答案
您是否检查过cfvC
不是nil
?如果 @"UICategoryFeedController"
与 Storyboard中的标识符不匹配,则可能会出现这种情况。我问是因为这会使 viewControllers
成为一个空数组,这将解释您的日志记录结果。
另一方面,我猜你有一个设置,其中 UITabBarController
中的每个选项卡都包含自己的导航堆栈(即有四个 UINavigationController
实例,设置为标签栏 Controller 的 viewControllers
)。其次,我假设您示例中的 self
是 View Controller D
。这意味着无论何时在此方法中调用 self.navigationController
,无论选择了哪个选项卡,返回的都是选项卡 D 中的导航 Controller 。要在选项卡 B 中设置 View Controller ,您必须在选项卡 B 中获取对导航 Controller 的引用。如果我的假设是正确的,您可以执行以下操作:
UINavigationController *tabBNavigationController = tabbarController.viewControllers[1];
在这个 导航 Controller 上设置您的viewControllers
数组应该可以解决问题。另外,你是对的,你不想做 pushViewController
位。
关于ios - 导航堆栈在 setViewControllers 之后为零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25362698/
我有一个简单的问题:我的自定义 UITabBarController子类同时覆盖 setViewControllers:和 setViewControllers:animated: .在 Storyb
我正在尝试实现一个 PageViewController,当按下按钮时它会切换到不同的 ViewController。我可以在 viewDidLoad() 期间使用 setViewController
我正在尝试使用 NEXT 按钮更改 UIPageViewController 的当前 ViewController。所以我使用委托(delegate)在我的 mainViewController 中调
我遇到了一个奇怪的问题,我不知道这是我的错误(最有可能)还是 UINavigationController 中的错误。 我在我的应用程序中使用 UINavigationController。在某些情况
当我设置 UIPageViewController 时,我无法理解这行代码: [self.pageViewController setViewControllers:@[startingViewC
我遇到了一个非常奇怪的情况 - 调用 method UINAvigationController -> setViewControllers:animated: 导致应用程序崩溃。仅在 iOS 10.
我正在尝试使用名为 Remenu 的第三方下拉菜单,可在此处找到 https://github.com/romaonthego/REMenu 菜单正在出现,但是当我尝试单击某个项目时,我总是看到黑屏。
我正在尝试使用导航菜单从一个 View Controller 转到另一个 View Controller 。我的问题是它将从 AddNewHomeTableViewController 访问代码,但不
这是我的层次结构: A - B - C - D (tabs) | | | | | | | | ----------------> AddEventViewController
我发现 setNavigationBarHidden 在 setViewControllers 之后不起作用? 这是我的代码: HomeNavController.swift: class HomeN
我有一个 UIPageViewController,其中有两个 UIViewController 作为子级。我希望用户能够在 subview 之间进行分页,但我也希望能够自动调用页面。 我已经尝试了使
“无法使用类型为‘([AnyObject],方向:UIPageViewControllerNavigationDirection,动画:Bool,完成:nil)’的参数列表调用”‘setViewCon
一段时间以来,我一直在处理这个(有点)随机错误,但无法找出问题所在。上下文:我正在创建一个 UISplitView iPad 应用程序,它在主视图中有一个 UINavigationController
我正在使用具有水平滚动功能的 UIPageViewController...只要用户滚动,UIPageControl 就会正常工作,以编程方式跳转到下一页或上一页时会出现问题 [self.pageVi
注意到奇怪的事情:当您使用 setViewControllers:animated 替换 UINavigationController 中的 View Controller 堆栈时:动画过程中显示后退
我的 UINavigationController 有一个奇怪的问题。 我编写了一个应用程序来显示三个级别的数据。 ( Root View :选择数据 I,第二 View :选择数据 II,第三 Vi
我第一次尝试让 UIPageViewController 工作,但每当我尝试设置它的 View Controller 时,我似乎都遇到了麻烦。 override func viewDidLoad()
问题来了。我在 UINavigationController 中使用以下代码来交换 rootViewController。我需要能够在多个不同的屏幕之间交换 rootViewController 并允
我正在制作一个使用 UIPageViewController 在页面之间导航的应用程序。一切正常,除了当我尝试手动更改使用 setViewControllers 显示的 View Controller
我尝试在用户点击按钮时更改导航 Controller 中的 View Controller ,因此我声明了以下代码: if standingsViewController == nil { st
我是一名优秀的程序员,十分优秀!