UINavigation 推送新的根控制器 [英] UINavigation pushing a new root controller

查看:14
本文介绍了UINavigation 推送新的根控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将新的根控制器推送到导航堆栈,但使用侧面显示菜单.

I am trying to push a new root controller to a navigation stack, but using a side reveal menu.

我的应用委托具有以下内容:

My app delegate has the following:

    welcomeViewController = [[MyWelcomeViewController  alloc] initWithNibName:@"MyWelcomeViewController" bundle:nil];
navController = [[UINavigationController alloc] initWithRootViewController:welcomeViewController];
navController.navigationBarHidden = YES;

// Then we setup the reveal side view controller with the root view controller as the navigation controller
self.revealSideViewController = [[PPRevealSideViewController alloc] initWithRootViewController:navController];
[self.revealSideViewController setDirectionsToShowBounce:PPRevealSideDirectionNone];
[self.revealSideViewController setPanInteractionsWhenClosed:PPRevealSideInteractionContentView | PPRevealSideInteractionNavigationBar];

// Then we make the window root view controller the reveal side view controller
self.window.rootViewController = self.revealSideViewController;

一旦显示欢迎视图控制器,用户就会登录.登录后,以下流程会从 App Delegate 再次运行.

Once the welcome view controller is displayed, the user logs in. Once logged in the following process runs again from the App Delegate.

self.navController.navigationBarHidden = NO;
[self.navController setTitle:@"Home"];
[self.navController pushViewController:homeViewController animated:NO];

然后我有一个侧视图控制器设置,它是一个带有自定义单元设置的表格视图.

I then have a side view controller setup which is a table view with custom cells setup.

选择一行后,我需要将新的根控制器推送到导航控制器上.我通过在选定单元格的表格视图中使用以下内容来尝试此操作.

When a row is selected I need to push a new root controller onto the navigation controller. I try this by using the following in the table view for the cell selected.

MyAccountViewController *accountViewController = [[MyAccountViewController alloc] init];
[self.navigationController setViewControllers:[NSArray arrayWithObject:accountViewController] animated:NO];

不幸的是,这并没有做任何事情.如果我将代码添加到 App Delegate,然后从表视图控制器调用该方法,那么它可以工作,但不能从表视图本身的 .m 文件中调用.添加日志我可以看到上面是运行的,只是没有做任何事情.

Unfortunately this does not do anything. If I add the code to the App Delegate and then call the method from the table view controller then it works, however not from the .m file for the table view itself. Adding a log I can see the above is run, just does not do anything.

我不确定我是否需要对上述内容做任何不同的事情.例如,完全弹出当前显示的视图,然后重新创建导航控制器和 PPRevealSideViewController.如果我应该这样做,我不确定如何弹出所有当前视图,然后将新视图推送到窗口,而不是从 AppDelegate.

I am unsure if I need to do anything different on the above. For example, completely pop the views currently shown, then create the navigation controller and PPRevealSideViewController all over again. If I am supposed to, I am unsure how to pop all the current views to then push the new to the window, not from the AppDelegate.

我不希望在 App Delegate 中使用这个的原因是因为它是处理这个问题的不正确方法,然后我需要为每个我想从菜单中推送的新根控制器一个单独的方法,所以 App代表会变得非常大.

The reason I do not want this in the App Delegate is because it is the incorrect way to approach this, and I would then need a separate method for each new root controller I would like to push from the menu, so the App Delegate would become very large.

推荐答案

在你的 AppDelegate.h 中添加这样的内容:

Add something like this to your AppDelegate.h:

#define XAppDelegate ((AppDelegate *)[[UIApplication sharedApplication] delegate])

现在您可以从项目中的任何 .m 文件访问 AppDelegate 的任何 iVar.

Now you can access any iVar of AppDelegate from any .m file in your project.

 MyAccountViewController *accountViewController = [[MyAccountViewController alloc] init];
 [XAppDelegate.navController pushViewController:accountViewController animated:NO];

确保添加正确的导入.还有一件事:完成登录后,最好从导航控制器中弹出登录窗口.

Make sure you add the correct imports. One more thing: It's good to pop the login window from your navcontroller once you are done Logging in.

希望这会有所帮助.

这篇关于UINavigation 推送新的根控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆