UINavigation pushing a new root controller

ⅰ亾dé卋堺 提交于 2019-12-02 06:06:53

Check UINavigationController.h:

@interface UIViewController (UINavigationControllerItem)
@property(nonatomic,readonly,retain) UINavigationController *navigationController; // If this view controller has been pushed onto a navigation controller, return it.

It means when you do myViewController.navigationController you will either get nil if myViewController is not pushed to any navController or the navController reference myViewController is pushed into.

As I understand your tableViewController is not pushed into the navController stack, that means you can't get the navController with tableViewController.navigationController. Instead you'll need to use anyViewControllerInTheStack.navigationController or if the navController is the rootViewController of your keyWindow, by

((UINavigationController*)[[UIApplication sharedApplication] keyWindow].rootViewController)

Add something like this to your AppDelegate.h:

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

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.

Hope this helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!