我在加载应用程序时创建了一些逻辑,我可以根据我在 plist 中设置的一些值从 3 个不同的视图加载。
这就是我的代码的样子
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//sets context for coredata
CoreDataController *coreDataController = [CoreDataController sharedManager];
coreDataController.managedObjectContext = self.managedObjectContext;
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
PrefsController *prefsController = [[PrefsController alloc] init];
NSDictionary *prefsDictionary = [prefsController readPrefs];
NSLog(@"%@", prefsDictionary);
NSString *projectListBoolString = [prefsDictionary objectForKey:@"ProjectListAvailable"];
NSString *installsBoolString = [prefsDictionary objectForKey:@"InstallsAvailable"];
NSString *finishinBoolString = [prefsDictionary objectForKey:@"FinishingAvailable"];
if (([projectListBoolString isEqualToString:@"T"]) && ([installsBoolString isEqualToString:@"F"]) && ([finishinBoolString isEqualToString:@"F"])) {
self.getProjectListViewController = [[GetProjectListViewController alloc] initWithNibName:@"GetProjectListViewController" bundle:nil];
self.window.rootViewController = self.getProjectListViewController;
[self.window makeKeyAndVisible];
}
else if (([projectListBoolString isEqualToString:@"T"]) && ([installsBoolString isEqualToString:@"T"]) && ([finishinBoolString isEqualToString:@"T"])) {
self.currentProjectListViewController = [[CurrentProjectListViewController alloc] initWithNibName:@"CurrentProjectListViewController" bundle:nil];
self.window.rootViewController = self.currentProjectListViewController;
[self.window makeKeyAndVisible];
}
else {
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
}
return YES;
}
我希望能够然后加载和卸载 UIViewControllers(包括通过使用按钮等从内存中删除)。
我不想使用基于导航的控制器,因为我希望视图是静态的或单独的,如果这更有意义的话。
如果有人可以向我展示一些示例代码,以将新的 UIViewController 加载到窗口并删除旧的 UIViewController,这将非常受欢迎。
但是,我不确定正确的处理方法是什么,甚至代码的外观如何。
任何帮助将不胜感激。