簡體   English   中英

在應用中使用多個故事板的最佳方法

[英]Best way to use multiple storyboards in app

我目前正在開發一個將使用多個故事板的應用程序,如下所示:

1)login.storyboard(處理注冊和登錄)

2)main.storyboard(處理游戲選項和選擇)

3)settings.storyboard(處理游戲的設置)

4)game.storyboard(精打游戲)

我目前在NSUserDefaults中測試會話令牌,如果存在,則使用以下命令加載main.storyboard或auth.storyboard:

NSUserDefaults *tagDefaults = [NSUserDefaults standardUserDefaults];

if (![tagDefaults objectForKey:@"session_token"]) {

    NSLog(@"session token not found");
    NSString *storyboardId = @"nonauth";
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"login" bundle:nil];
    UIViewController *initViewController = [storyboard instantiateViewControllerWithIdentifier:storyboardId];

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

} else {

    NSString *storyboardId = @"init";
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"init" bundle:nil];
    UIViewController *initViewController = [storyboard instantiateViewControllerWithIdentifier:storyboardId];

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.rootViewController = initViewController;
    [self.window makeKeyAndVisible];
}

從登錄屏幕(如果登錄返回有效)中,我可以使用它在NSURLSession完成處理程序中從login.storyboard切換到main.storyboard:

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"main" bundle:nil];
    UINavigationController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"main"];
    self.view.window.rootViewController = viewController;

我的兩個問題是:A)這是實現此目標的正確方法嗎? B)從login.storyboard執行切換之后,在main.storyboard實際加載之前會有相當大的延遲(延遲20-30秒),有沒有辦法加快或改進代碼以避免這種延遲?

提前致謝。

Ĵ

  1. 不要更改根視圖控制器。 沒有必要。 一個應用程序在整個生命周期內應具有一個根視圖控制器。 如果要用視圖控制器的視圖完全替換接口,請顯示該視圖控制器。 出現的視圖控制器可能會出現,並且在應用程序的整個生命周期中都將停留在那里。 (實際上,如果登錄界面是稀有界面,則將主界面設為主界面並在其頂部顯示登錄界面會更有意義。)

  2. 同樣,不需要同時使用登錄情節提要和主情節提要。 這些界面集可以在同一情節提要中,因此無需加載新的情節提要。

我傾向於模態呈現登錄VC。 我總是加載主VC。 如果不存在會話令牌,那么我將以動畫形式呈現登錄VC。 實際上,這使它看起來好像啟動時存在登錄視圖。 用戶成功登錄后,您可以使用典型的模式關閉(從屏幕底部掉下來)關閉,也可以執行淡入淡出的操作。

對於情節提要,我個人使用多個。 如果您的應用程序不平凡,則SB中的視圖數可能會變得非常大。 這可能很難管理-在海景中找到想要的人既煩人又耗時。 此外,它使我的機器陷入癱瘓。 也許最重要的是,如果您正在使用具有源代碼管理的團隊(您絕對應該使用),那么嘗試管理對單個SB的訪問確實很煩人。 通常,如果多個開發人員修改單個SB,則無法合並更改。 至少有多個,您可以將不同的人分配給不同的任務,每個任務都與自己的SB相關。 擁有多個SB並沒有性能優勢(只有實例化的視圖占用內存)。 但是從開發效率的角度來看,還是有優勢的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM