• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

iOS应用具有多个视图控制器

IOS 来源:Angie 19次浏览

我上的appDelegate当前的应用程序加载main.xib屏幕仅包含两个图像背景和标志。代码后面的这个屏幕确定用户是否登录系统,如果不是,它将显示登录,否则它将显示仪表板。iOS应用具有多个视图控制器

的应用已被创建为单个视图应用,示例代码的appDelegate的:

// Override point for customization after application launch. 
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) 
{ 
    self.Main = [[vcMain alloc] initWithNibName:@"vcMain" bundle:nil]; 
    self.window.rootViewController = self.Main; 
    [self.window makeKeyAndVisible]; 
} 
else 
{ 
    self.MainiPad = [[vcMain_iPad alloc] initWithNibName:@"vcMain_iPad" bundle:nil]; 
    self.window.rootViewController = self.MainiPad; 
    [self.window makeKeyAndVisible]; 
} 

在的main.m上viewDidLoad中我有以下:

if (islogged) 
{ 
    vcDashboard *vcDash = [[vcDashboard alloc] initWithNibName:@"vcDashboard" bundle:nil]; 
    _ncMain = [[UINavigationController alloc] initWithRootViewController:vcDash]; 
    _ncMain.navigationBar.barStyle = UIBarStyleBlackOpaque; 
    _ncMain.view.frame = self.view.bounds; 
    [self.view addSubview:_ncMain.view]; 
    ViewActive = vDash; 
} 
else 
{ 
    vcLogin *login = [[vcLogin alloc] initWithNibName:@"vcLogin" bundle:nil]; 
    login.modalPresentationStyle = UIModalPresentationFormSheet; 
    login.view.frame = self.view.bounds; 
    [self presentViewController:login animated:YES completion:nil]; 
} 

有在信息中心提供的菜单按钮向用户呈现一系列选项中选择另一个画面,按下时会激活以下方法:

- (void)displayView:(NSString *)strView Notification:(NSNotification *)notification{ 

if(_ncMain) 
{ 
    [_ncMain.view removeFromSuperview]; 
    _ncMain = nil; 
} 

if ([strView isEqual: @"Dashboard"]) 
{ 
    vcDashboard *vcDash = [[vcDashboard alloc] initWithNibName:@"vcDashboard" bundle:nil]; 
    _ncMain = [[UINavigationController alloc] initWithRootViewController:vcDash]; 
    _ncMain.navigationBar.barStyle = UIBarStyleBlackOpaque; 
    _ncMain.view.frame = self.view.bounds; 
    [self.view addSubview:_ncMain.view]; 
    ViewActive = vDash; 
} 
else if ([strView isEqual: @"Catalog"]) 
{ 
    vcCatalog *vcCat = [[vcCatalog alloc] initWithNibName:@"vcCatalog" bundle:nil]; 
    _ncMain = [[UINavigationController alloc] initWithRootViewController:vcCat]; 
    _ncMain.navigationBar.barStyle = UIBarStyleBlackOpaque; 
    _ncMain.view.frame = self.view.bounds; 
    [self.view addSubview:_ncMain.view]; 
    ViewActive = vCatalog; 
} 
else if ([strView isEqual: @"News"]) 
{ 
    vcNews *vcNew = [[vcNews alloc] initWithNibName:@"vcNews" bundle:nil]; 
    _ncMain = [[UINavigationController alloc] initWithRootViewController:vcNew]; 
    _ncMain.navigationBar.barStyle = UIBarStyleBlackOpaque; 
    _ncMain.view.frame = self.view.bounds; 
    [self.view addSubview:_ncMain.view]; 
    ViewActive = vNews; 
} 

}

我怀疑这里是我好像不知道这是当一个选项是从该菜单中选择屏幕之间切换的正确方法,如果是正确的,总是addSubview到主屏幕。不知道使用导航控制器模板是否是一种解决方案。我担心应用程序在完成所有这些时所消耗的内存,同时我也正在项目中使用ARC。


===========解决方案如下:

我建议你避免addSubview方法如果可能的话。 UiNAvigationController为您提供了一种处理不同viewController的好方法。例如,如果您使addSubview发生changeRotation事件,则不会调用该事件。当你做出一个流行的viewController是dealloced。

祝你好运!


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)