gpt4 book ai didi

ios - 如何调用 didFinishLaunchingWithOptions 中的对象?

转载 作者:行者123 更新时间:2023-11-29 03:51:32 25 4
gpt4 key购买 nike

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{


if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
CGSize result = [[UIScreen mainScreen] bounds].size;
if(result.height == 480)
{
// iPhone Classic
NSLog(@"iPhone 4");
}
if(result.height == 568)
{
// iPhone 5
NSLog(@"iPhone 5");
}
}

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

SideMenuViewController *leftMenuViewController = [[SideMenuViewController alloc] init];



ContainerOfSideMenuByVeerViewController *container = [ContainerOfSideMenuByVeerViewController
containerWithCenterViewController:[self navigationController]
leftMenuViewController:leftMenuViewController];

self.window.rootViewController = container;
[self.window makeKeyAndVisible];

return YES;

}

每当我更改 Controller 时,我都希望 leftMenuViewController 中有一些值,但它只加载一次,因为 didFinishLaunchingWithOptions 在应用程序启动时加载一次。那我该怎么办?

最佳答案

将其存储为属性。

在您的 AppDelegate.h 文件中:

@property (nonatomic, strong) ContainerOfSideMenuByVeerViewController *container;

在您的 AppDelegate.m 文件中:

self.container = [ContainerOfSideMenuByVeerViewController
containerWithCenterViewController:[self navigationController]
leftMenuViewController:leftMenuViewController];
self.window.rootViewController = container;
[self.window makeKeyAndVisible];

然后,当您想要更改 leftMenuViewController 时,您可以从任何您想要的地方调用以下代码:

AppDelegate *delegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];
[delegate.container setLeftMenuViewController:...someViewController];

Apple's Documentation中有一个很好的属性介绍。 .

此外,在检查大小时,您应该使用 if... else... 而不是两个 if 语句:

CGSize result = [[UIScreen mainScreen] bounds].size;
if(result.height == 480.0f)
{
// iPhone Classic
NSLog(@"iPhone 4");
}
else if(result.height == 568.0f)
{
// iPhone 5
NSLog(@"iPhone 5");
}

关于ios - 如何调用 didFinishLaunchingWithOptions 中的对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17008402/

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