2013-06-13 27 views
1

我正在創建一個應用程序,並在用戶第一次使用時,我將需要他們給我他們的API令牌來訪問應用程序,但我只需要這個登錄顯示一次,並且之後我會將標記存儲在NSUserDefaults中。ios上的一次登錄屏幕

我的問題是,我使用的故事板和理論上的登錄屏幕將是我的根視圖...但在我有令牌後,我想跳過這部分,那麼我該怎麼做呢?我應該爲登錄屏幕創建一個分離的xib文件嗎?

然後在應用程序委託中,我會檢查令牌是否存在並調用xib或故事板文件。不知道這是否是最好的方法,是否有人會推薦更有效的東西?

感謝

回答

5

enter image description here

添加stoyboardId在故事板

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
NSString *identifier; 
BOOL isSaved = [[NSUserDefaults standardUserDefaults] boolForKey:@"loginSaved"]; 
if (isSaved) 
    { 
    [email protected]"home"; 
    } 
else 
    { 
    [email protected]"login"; 
    } 
UIStoryboard * storyboardobj=[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; 
UIViewController *screen = [storyboardobj instantiateViewControllerWithIdentifier:identifier]; 
[self.window setRootViewController:screen]; 
return YES; 
} 
+0

登錄和主視圖控制器上的IF,該identfier是假設調用SEGUE?或者我應該聲明什麼類型的標識符變量? –

+0

也storyboardobj是我根據你的截圖設置故事板ID,對吧? –

+1

查看我編輯過的答案...... – Kalpesh