【发布时间】:2013-10-11 13:55:55
【问题描述】:
我在 appDelegate 上的当前应用程序加载了一个 main.xib 屏幕,其中仅包含两个图像背景和徽标。代码后面的这个屏幕确定用户是否登录系统,如果没有,它将显示登录信息,否则将显示仪表板。
应用程序已创建为单视图应用程序,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;
}
}
我的疑问是,当从此菜单中选择一个选项时,我似乎不知道这是否是在屏幕之间切换的正确方法,以及是否始终将添加子视图添加到主屏幕是否正确。不知道使用navigationcontroller 模板是否是一个解决方案。我担心应用程序在执行所有这些操作时消耗的内存,而且我目前正在项目中使用 ARC。
【问题讨论】:
-
查看ios中的视图包含模式。 Viewcontrollers 可以有子 viewcontrollers 有他们自己的视图。这是一种非常简洁优雅的方式,可以将您的应用分解为可插入的小组件
标签: ios viewcontroller navigationcontroller