0
- (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;

}

I want some value in leftMenuViewController, whenever I change my controller, but it loads only one time as didFinishLaunchingWithOptions loads once as app launches. So what should I do?

4

1 回答 1

1

将其存储为属性。

在您的 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");
}
于 2013-06-09T10:02:36.870 回答