gpt4 book ai didi

ios - 在 xcode6 中的 UINavigationController segues 之间切换?

转载 作者:行者123 更新时间:2023-11-28 18:59:03 24 4
gpt4 key购买 nike

我有一个 View Controller ,可以呈现 2 个导航 View Controller ,每个 View Controller 都有自己的 View Controller 堆栈:

enter image description here

现在我希望能够随时切换这些导航 Controller 。我通过新的展示功能展示它们。例如,我深入了解顶部导航 Controller 的层次结构,我想切换到底部。我可以只调用 WebView Controller 吗

UIViewController *rootController = (UIViewController *)[UIApplication sharedApplication].keyWindow.rootViewController;
[rootController performSegueWithIdentifier:@"sessionsNavigationController" sender:nil];

这是否会将顶部 Controller 保留在堆栈上并将底部 Controller 放在它上面,它会取代它们吗?

英语不是我的母语,但如果我不清楚我想要什么,我会尝试提供一些额外的信息。

最佳答案

最好的方法是在 AppDelegate.m 中自己处理切换

UINavigationController* firstNVC;
UINavigationController* secondNVC;
BOOL showingFirst;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//Store two local pointers to the Navigation Controllers you want to switch between
self.firstNVC = [[UIStoryboard storyboardWithName:@"main" bundle:nil] instantiateViewControllerWithIdentifier:@"firstNVC"];
self.secondNVC = [[UIStoryboard storyboardWithName:@"main" bundle:nil] instantiateViewControllerWithIdentifier:@"secondNVC"];
//Add yourself to listen for a notification to switch controllers
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(switchViews:)
name:@"switchViews"
object:nil];
//Set toggle bool
showingFirst = TRUE;
//Set first view to show
self.window.rootViewController = self.firstNVC;
return YES;
}

- (void)switchViews:(NSNotification *)notification
{
//Swap viewcontrollers
if(showingFirst)
self.window.rootViewController = self.secondNVC;
else
self.window.rootViewController = self.firstNVC;
//Toggle bool
showingFirst = !showingFirst;
}

然后在您的应用程序中您想要切换 Controller 的任何地方,只需使用此行向您的 AppDelegate 发布通知

[[NSNotificationCenter defaultCenter] postNotificationName:@"switchViews" object:self userInfo:nil];

关于ios - 在 xcode6 中的 UINavigationController segues 之间切换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28411272/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com