2012-04-09 4 views
1

私は自分のサーバーからほとんどのデータを取得するWebベースのアプリケーションを持っています。私のログインビューでは、いくつかのユーザ情報を入力し、入力した値がデータベースのものと一致する場合、サーバにGETリクエストを作成します(loginMethodという方法でこれらの処理を行います)。新しいviewcontroller(私のメインビュー)を押してください。何もここまでは大丈夫ですが、私はAppDelegateクラスにコントロールを追加したいのですが、デフォルトのデータがない場合(つまり、初めての場合)、保存したデータがあればログインビューコントローラを表示したいメインメニューを表示します。私はいくつかの方法を試みましたが、いつも失敗しました。ここに私のコードは次のとおりです。それはクラッシュしませんが、それは、黒い画面を表示するNSUserDefaultsを取得し、2回目のインストール後に表示する方法

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

EDIT。値の保存に問題はありません

+0

「失敗」とはどういう意味ですか?クラッシュ? – Saphrosit

+0

@Saphrositいいえ空白の&黒い画面を表示する – ilhnctn

答えて

-1

は、値が存在しない場合はobjectForKeyメソッドがnilを返し、空のstrignaではないとみなし、最初の条件をチェックしないと仮定します。

関連する問題