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

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

Storyboard登錄屏幕的最佳做法,在注銷時處理數(shù)據(jù)清除

Storyboard登錄屏幕的最佳做法,在注銷時處理數(shù)據(jù)清除

阿波羅的戰(zhàn)車 2019-08-23 10:53:09
Storyboard登錄屏幕的最佳做法,在注銷時處理數(shù)據(jù)清除我正在使用Storyboard構(gòu)建iOS應(yīng)用程序。根視圖控制器是一個標(biāo)簽欄控制器。我正在創(chuàng)建登錄/注銷過程,它基本上工作正常,但我有一些問題。我需要知道設(shè)置這一切的最好方法。我想完成以下任務(wù):首次啟動應(yīng)用程序時顯示登錄屏幕。登錄后,轉(zhuǎn)到選項卡欄控制器的第一個選項卡。任何時候他們在此之后啟動應(yīng)用程序,檢查他們是否已登錄,并直接跳到根選項卡欄控制器的第一個選項卡。當(dāng)他們手動單擊注銷按鈕時,顯示登錄屏幕,并清除視圖控制器中的所有數(shù)據(jù)。到目前為止我所做的是將根視圖控制器設(shè)置為Tab Bar Controller,并為我的Login視圖控制器創(chuàng)建了一個自定義segue。在我的Tab Bar Controller類中,我檢查它們是否在viewDidAppear方法內(nèi)登錄,然后執(zhí)行segue:[self performSegueWithIdentifier:@"pushLogin" sender:self];我還設(shè)置了需要執(zhí)行注銷操作的通知: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(logoutAccount) name:@"logoutAccount" object:nil];注銷后,我清除Keychain中的憑據(jù),運行[self setSelectedIndex:0]并執(zhí)行segue以再次顯示登錄視圖控制器。這一切都很好,但我想知道:這個邏輯應(yīng)該在AppDelegate嗎?我還有兩個問題:第一次啟動應(yīng)用程序時,Tab Bar Controller會在執(zhí)行segue之前短暫顯示。我已經(jīng)嘗試過移動代碼viewWillAppear但是segue不會那么早。當(dāng)他們注銷時,所有數(shù)據(jù)仍然在所有視圖控制器中。如果他們登錄到新帳戶,舊帳戶數(shù)據(jù)仍會顯示,直到刷新為止。我需要一種方法在注銷時輕松清除它。我愿意改變它。我已經(jīng)考慮將登錄屏幕設(shè)置為根視圖控制器,或者在AppDelegate中創(chuàng)建導(dǎo)航控制器來處理所有事情......我只是不確定此時最好的方法是什么。
查看完整描述

3 回答

?
三國紛爭

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

在您的didFinishLaunchingWithOptions中的appDelegate.m中


//authenticatedUser: check from NSUserDefaults User credential if its present then set your navigation flow accordingly


if (authenticatedUser) 

{

    self.window.rootViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateInitialViewController];        

}

else

{

    UIViewController* rootController = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"LoginViewController"];

    UINavigationController* navigation = [[UINavigationController alloc] initWithRootViewController:rootController];


    self.window.rootViewController = navigation;

}

在SignUpViewController.m文件中


- (IBAction)actionSignup:(id)sender

{

    AppDelegate *appDelegateTemp = [[UIApplication sharedApplication]delegate];


    appDelegateTemp.window.rootViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateInitialViewController];

}

在文件MyTabThreeViewController.m中


- (IBAction)actionLogout:(id)sender {


    // Delete User credential from NSUserDefaults and other data related to user


    AppDelegate *appDelegateTemp = [[UIApplication sharedApplication]delegate];


    UIViewController* rootController = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"LoginViewController"];


    UINavigationController* navigation = [[UINavigationController alloc] initWithRootViewController:rootController];

    appDelegateTemp.window.rootViewController = navigation;


}

Swift 4版本


應(yīng)用委托中的didFinishLaunchingWithOptions假設(shè)您的初始視圖控制器是在TabbarController中簽名的。


if Auth.auth().currentUser == nil {

        let rootController = UIStoryboard(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "WelcomeNavigation")

        self.window?.rootViewController = rootController

    }


    return true

在注冊視圖控制器中:


@IBAction func actionSignup(_ sender: Any) {

let appDelegateTemp = UIApplication.shared.delegate as? AppDelegate

appDelegateTemp?.window?.rootViewController = UIStoryboard(name: "Main", bundle: Bundle.main).instantiateInitialViewController()

}

MyTabThreeViewController


 //Remove user credentials

guard let appDel = UIApplication.shared.delegate as? AppDelegate else { return }

        let rootController = UIStoryboard(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "WelcomeNavigation")

        appDel.window?.rootViewController = rootController


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

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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