这几天我一直在研究这个问题,但我无法弄清楚。
-> 基本上我想实现一个简单的登录 View ,单击时有一个按钮,转到导航 Controller (在我的例子中是“viewController”,带有链接到其他 View 的迷你数学游戏的按钮)。
-> 在登录屏幕上单击按钮时,应首先显示登录屏幕,而不是导航 Controller 的 Root View
-> 我尝试在单击登录屏幕的按钮时声明导航 Controller ,但这似乎不起作用
-> 只能在 apple delegate 中初始化导航 Controller 是否安全?
目前我在我的 apple delegate 中声明和设置我的导航 Controller :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
UINavigationController *navigationViewController = [[UINavigationController alloc] initWithRootViewController:self.viewController]; // self.viewController is the main screen
self.window.rootViewController = navigationViewController; // set root to navigationViewController
[self.window makeKeyAndVisible];
return YES;
}
任何想法将不胜感激。感谢您的宝贵时间!
最佳答案
您在应用委托(delegate)中的代码看起来没问题。 NavigationController 不需要在 AppDelegate 中声明。在您的情况下,在按下登录按钮时声明它绝对可以。
在登录事件中试试这个:
UIViewController *nextVC = [[UIViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:nextVC];
[self presentViewController:navController animated:YES completion:^{
}];
关于导航 Controller 之前的 iOS 初始登录 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19555415/