[英]UINavigationViewController setViewControllers not setting correctly
I am having an issue where calling setViewControllers
does not set my array of view controllers to my navigation view controller. 我遇到一个问题,即调用
setViewControllers
不会将我的视图控制器数组设置为导航视图控制器。 I am doing this in a block, so I'm not sure if it's a UI issue (but I have tried solving this by setting my view controllers in the main queue). 我正在执行此操作,所以我不确定这是否是UI问题(但我尝试通过在主队列中设置视图控制器来解决此问题)。
[self thisIsABlock:^(){
UIViewController3 *viewController3 = [storyboard instantiateViewControllerWithIdentifier:@"HeyHey"];
// viewController3 is not nil
NSMutableArray *array1 = [self.navigationController.viewControllers mutableCopy];
// array1 contains [viewController1, viewController2]
[array1 addObject:viewController3];
[self.navigationController setViewControllers:array1 animated:NO];
// Now array1 contains [viewController1, viewController2, viewController3]
NSMutableArray *array2 = [self.navigationController.viewControllers mutableCopy];
// array2 only contains [viewController1, viewController2]
}];
This block of code is an abstraction of what I'm doing in my codebase. 此代码块是我在代码库中所做的事情的抽象。 I may be missing some crucial code that is causing this issue but I hope that someone has encountered this problem before and knows what the problem is.
我可能会丢失一些导致此问题的关键代码,但我希望有人以前遇到过此问题,并且知道问题出在哪里。 Thanks!
谢谢!
// EDIT 1: I am calling this at - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
//编辑1:我在
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
处调用此- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
When I open the app from background to foreground, my code works. 当我从后台打开应用程序到前台时,我的代码有效。
Above code is correct, but you can provide valid data like this, 上面的代码是正确的,但是您可以提供这样的有效数据,
YourViewController *viewController3 = [self.storyboard instantiateViewControllerWithIdentifier:@"YourStoryBoardViewControllerIdentifer"];
hope it helps you. 希望对您有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.