2011-08-05 64 views
0

我在我的應用程序中使用了主窗口,其中有一個TabController用於我的主菜單。iOS:如何顯示登錄表單?

現在我想爲我的應用程序提供登錄表單。 我添加了一個視圖(LoginViewController),並顯示在開始這樣的觀點:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
// Override point for customization after application launch. 
// Add the tab bar controller's current view as a subview of the window 

self.window.rootViewController = self.tabBarController; 
[self.window makeKeyAndVisible]; 

LoginViewController *lvc = [[LoginViewController alloc]  initWithNibName:@"LoginViewController" bundle:nil]; 
lvc.delegate = self; 
[self.tabBarController presentModalViewController:lvc animated:false]; 
[lvc release]; 

return YES; 
} 

接下來,我必須在我的觀點登錄的檢查,還行。

現在我嘗試在此之後關閉視圖。 爲此,我尋找了一圈,發現這裏的問題是:present modal view controller

我所有的東西添加到我的項目,但得到一個錯誤在此代碼:

#import <UIKit/UIKit.h> 

@interface Animexx3AppDelegate : NSObject <UIApplicationDelegate, 
          UITabBarControllerDelegate, LoginViewControllerDelegate> 
{ 
UIWindow *window; 
UITabBarController *tabBarController; 
} 

@property (nonatomic, retain) IBOutlet UIWindow *window; 

@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController; 

@end 

這意味着「找不到協議LoginViewControllerDelegate」看齊2/3。

加在該行「lvc.delegate =自我」我知道,告訴我一個警告「分配給‘ID’從類型不兼容‘Animexx3AppDalagte’。

什麼了我錯了?

+0

請將'false'布爾文字改爲'NO',它與Cocoa定義的文字相同。你會注意到你的代碼讀得更好,和我一樣的Objective-C程序員在我們看到你的代碼時不會畏縮:)。 – PeyloW

回答

2

您需要導入,你聲明的LoginViewControllerDelegate協議的頭文件。最有可能的LoginViewController.h文件。

0

有很多次努力之後,我們發表了一篇名爲CLHoppingViewController一個開源庫,它處理正是這種情景。

所以,你的情況,你會做這樣的事情來形容啓動流程:

UIViewController *loginViewController; 
UIViewController *mainViewController; 

if (user_not_logged_in) { 
    [self hopToViewController:loginViewController then:^{ 
    [self hopToViewController:mainViewController then:nil]; 
    }]; 
} 
else { 
    [self hopToViewController:mainViewController then:nil]; 
} 

庫可以支持更加先進的條件序列。例如,您可以顯示啓動畫面,有條件地顯示入職UX等。

有一個簡短的教程here