第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

有條件地從AppDelegate的情節(jié)提要中的不同位置開始

有條件地從AppDelegate的情節(jié)提要中的不同位置開始

明月笑刀無情 2019-12-09 14:11:19
我有一個故事板設(shè)置了正常的登錄名和主視圖控制器,主視圖控制器是登錄成功后用戶導(dǎo)航到的視圖控制器。我的目標(biāo)是如果身份驗證(存儲在鑰匙串中)成功,則立即顯示主視圖控制器,如果身份驗證失敗,則顯示登錄視圖控制器?;旧?,我想在AppDelegate中執(zhí)行以下操作:// url request & response work fine, assume success is a BOOL here// that indicates whether login was successful or notif (success) {          // 'push' main view controller} else {          // 'push' login view controller}我知道方法performSegueWithIdentifier:但是該方法是UIViewController的實例方法,因此無法從AppDelegate中調(diào)用。如何使用現(xiàn)有的情節(jié)提要板來完成此任務(wù)?編輯:情節(jié)提要的初始視圖控制器現(xiàn)在是導(dǎo)航控制器,沒有連接任何東西。我使用了setRootViewController:區(qū)別,因為MainIdentifier是UITabBarController。這就是我的代碼:- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{            BOOL isLoggedIn = ...;    // got from server response    NSString *segueId = isLoggedIn ? @"MainIdentifier" : @"LoginIdentifier";    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];    UIViewController *initViewController = [storyboard instantiateViewControllerWithIdentifier:segueId];    if (isLoggedIn) {        [self.window setRootViewController:initViewController];    } else {        [(UINavigationController *)self.window.rootViewController pushViewController:initViewController animated:NO];    }    return YES;}歡迎提出建議/改進!
查看完整描述

3 回答

?
子衿沉夜

TA貢獻1828條經(jīng)驗 獲得超3個贊

我假設(shè)您的情節(jié)提要板被設(shè)置為“主情節(jié)提要板”(UIMainStoryboardFileInfo.plist中的鍵)。在這種情況下,UIKit將加載情節(jié)提要,并將其初始視圖控制器設(shè)置為窗口的根視圖控制器,然后再發(fā)送application:didFinishLaunchingWithOptions:到AppDelegate。


我還假設(shè)情節(jié)提要中的初始視圖控制器是導(dǎo)航控制器,您要將主視圖或登錄視圖控制器推入該導(dǎo)航控制器。


您可以向窗口詢問其根視圖控制器,并將performSegueWithIdentifier:sender:消息發(fā)送給它:


NSString *segueId = success ? @"pushMain" : @"pushLogin";

[self.window.rootViewController performSegueWithIdentifier:segueId sender:self];


查看完整回答
反對 回復(fù) 2019-12-09
?
絕地?zé)o雙

TA貢獻1946條經(jīng)驗 獲得超4個贊

我對這里提出的一些解決方案感到驚訝。


故事板中實際上不需要虛擬的導(dǎo)航控制器,無需在viewDidAppear:或任何其他黑客上隱藏視圖并觸發(fā)segues。


如果沒有在plist文件中配置情節(jié)提要,則必須自己創(chuàng)建窗口和根視圖控制器:


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{        

    BOOL isLoggedIn = ...;    // from your server response


    NSString *storyboardId = isLoggedIn ? @"MainIdentifier" : @"LoginIdentifier";

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];

    UIViewController *initViewController = [storyboard instantiateViewControllerWithIdentifier:storyboardId];


    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    self.window.rootViewController = initViewController;

    [self.window makeKeyAndVisible];


    return YES;

}

如果在應(yīng)用程序的plist中配置了故事板,則在調(diào)用application:didFinishLaunching:時將已經(jīng)設(shè)置了窗口和根視圖控制器,并且將在窗口上為您調(diào)用makeKeyAndVisible。


在這種情況下,它甚至更簡單:


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{        

    BOOL isLoggedIn = ...;    // from your server response


    NSString *storyboardId = isLoggedIn ? @"MainIdentifier" : @"LoginIdentifier";

    self.window.rootViewController = [self.window.rootViewController.storyboard instantiateViewControllerWithIdentifier:storyboardId];


    return YES;

}


查看完整回答
反對 回復(fù) 2019-12-09
?
慕虎7371278

TA貢獻1802條經(jīng)驗 獲得超4個贊

如果您的情節(jié)提要的入口點不是UINavigationController:


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {



    //Your View Controller Identifiers defined in Interface Builder

    NSString *firstViewControllerIdentifier  = @"LoginViewController";

    NSString *secondViewControllerIdentifier = @"MainMenuViewController";


    //check if the key exists and its value

    BOOL appHasLaunchedOnce = [[NSUserDefaults standardUserDefaults] boolForKey:@"appHasLaunchedOnce"];


    //if the key doesn't exist or its value is NO

    if (!appHasLaunchedOnce) {

        //set its value to YES

        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"appHasLaunchedOnce"];

        [[NSUserDefaults standardUserDefaults] synchronize];

    }


    //check which view controller identifier should be used

    NSString *viewControllerIdentifier = appHasLaunchedOnce ? secondViewControllerIdentifier : firstViewControllerIdentifier;


    //IF THE STORYBOARD EXISTS IN YOUR INFO.PLIST FILE AND YOU USE A SINGLE STORYBOARD

    UIStoryboard *storyboard = self.window.rootViewController.storyboard;


    //IF THE STORYBOARD DOESN'T EXIST IN YOUR INFO.PLIST FILE OR IF YOU USE MULTIPLE STORYBOARDS

    //UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"YOUR_STORYBOARD_FILE_NAME" bundle:nil];


    //instantiate the view controller

    UIViewController *presentedViewController = [storyboard instantiateViewControllerWithIdentifier:viewControllerIdentifier];


    //IF YOU DON'T USE A NAVIGATION CONTROLLER:

    [self.window setRootViewController:presentedViewController];


    return YES;

}

如果您的情節(jié)提要的入口點是UINavigationController替換項:


//IF YOU DON'T USE A NAVIGATION CONTROLLER:

[self.window setRootViewController:presentedViewController];

與:


//IF YOU USE A NAVIGATION CONTROLLER AS THE ENTRY POINT IN YOUR STORYBOARD:

UINavigationController *navController = (UINavigationController *)self.window.rootViewController;

[navController pushViewController:presentedViewController animated:NO];


查看完整回答
反對 回復(fù) 2019-12-09
  • 3 回答
  • 0 關(guān)注
  • 628 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號