2017-07-19 73 views
0

開發應用程序時,如果我只想測試一個屏幕,即選項卡視圖的第三個選項卡,如何在啓動時使應用程序在那裏導航?如何在啓動時自動導航到屏幕

+1

在您的故事板中,您將該視圖設置爲起始視圖。 – Steve

+0

有可能你正在尋找這個,伊恩:那個*總體視圖控制器*,它包含三個選項卡。在可能'viewWillAppear'中,只需將其更改爲所需的選項卡即可。 – Fattie

回答

1

我認爲一個好的解決方案是使用UI測試自動導航到應用程序中的正確位置。在測試結束時暫停斷點時,應用程序將手動播放。

1

AppDelegate中window屬性的rootViewController將成爲屏幕上顯示的第一個視圖控制器。您可以通過編程的編程或使用故事板

使其:

如果NavigationController是你的窗口RootViewController的,把自己的viewController擺在首位NavigationController的viewControllers的(指數爲0),這是一個陣列。它將默認顯示在屏幕上。

customNavigationController.viewControllers = [yourViewController] 

或簡單地設置您的viewController到RootViewController的窗前財產的appDelegate

AppDelegate.swift: 

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 
     // Override point for customization after application launch. 

     window = UIWindow(frame: UIScreen.main.bounds) 
     // window?.rootViewController = CustomTabBarViewController() 
     // customViewController will show on screen by default. 
     window?.rootViewController = CustomViewController() 
     window?.makeKeyAndVisible() 
     return true 
    } 

由Interface Builder:

檢查viewControlelr的屬性檢查器面板,並檢查「是初始視圖控制器「選項,然後您可以看到附加到此視圖控制器的簡單箭頭。

或:

附加標識您的viewController,並從故事板中獲取它,然後將其設置爲窗口對象的RootViewController的中的appDelegate

let testController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "testController") as! TestController 
let appDelegate = UIApplication.shared.delegate as! AppDelegate 
appDelegate.window?.rootViewController = testController 
相關問題