我有一个基于 Web 的应用程序,它从我的服务器获取几乎所有的数据。loginMethod
在我的登录视图中,我输入一些用户信息NSUserDefaults
并创建一个对服务器的 GET 请求(我在一个名为一个新的视图控制器(我的主视图)。到这里为止一切正常,但我想在我的 AppDelegate 类中添加一个控件,如果默认值中没有数据(意思是,如果是第一次)我想显示登录视图控制器,如果有我想要保存的数据显示主菜单。我尝试了几种方法,但总是失败。这是我的代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//uName, serve1r and pasword are my user defaults
NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
uName = [defaults objectForKey:@"kUsername1"];
serve1r = [defaults objectForKey:@"kServer1"];
pasword = [defaults objectForKey:@"kPassword1"];
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
if([uName isEqualToString:@""]){
//BNT_DetailViewController is my login class
detailViewController1 = [[[BNT_DetailViewController alloc] initWithNibName:@"BNT_DetailViewController" bundle:nil] autorelease];
navigationController = [[[UINavigationController alloc] initWithRootViewController:detailViewController1] autorelease];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
application.applicationIconBadgeNumber=0;}
else{
//controller is an instance of MainMenu class
controller = [[[MainMenu alloc] initWithNibName:@"MainMenu" bundle:nil] autorelease];
navigationController = [[[UINavigationController alloc] initWithRootViewController:controller] autorelease];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
application.applicationIconBadgeNumber=0;
}
return YES;
}
编辑它不会崩溃,但会显示黑屏。保存值没有问题