gpt4 book ai didi

ios - 创建第一个启动 View Controller

转载 作者:行者123 更新时间:2023-11-28 19:13:14 24 4
gpt4 key购买 nike

我正在尝试创建一个“初始设置页面”,如果应用程序在设备上首次启动时会显示该页面。

我是这样写的:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];


if ([[NSUserDefaults standardUserDefaults] boolForKey:@"HasLaunchedOnce"])
{
NSLog(@"not first launch");
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;

}
else
{
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HasLaunchedOnce"];
[[NSUserDefaults standardUserDefaults] synchronize];



NSLog(@"first launch");

}
}

现在我想创建一个 View Controller 并在应用程序第一次启动时推送到这个 View Controller 。

我需要做什么?

最佳答案

创建一个新的 View Controller 。在 appDelegate.h 文件中导入 header ,同时创建该类的一个名为 initialViewController 的实例变量。

改变你的其他条件,如:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"HasLaunchedOnce"])
{
NSLog(@"not first launch");
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
}
else
{
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HasLaunchedOnce"];
[[NSUserDefaults standardUserDefaults] synchronize];

self.initialViewController = [[InitialViewController alloc] initWithNibName:@"InitialViewController" bundle:nil];
self.window.rootViewController = self.InitialViewController;
NSLog(@"first launch");
}
[self.window makeKeyAndVisible];
return YES;
}

关于ios - 创建第一个启动 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13835475/

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