2017-02-11 14 views
4

내 appdelegate에서 globUs.hasName을 확인하고 싶습니다. 그럴 경우 앱의 Entry Point이 내 main 스토리 보드가되기를 원합니다. 그렇지 않은 경우 앱의 Entry Point이 내 newUser 스토리 보드가되기를 원합니다. 앱의 진입 점을 어떻게 설정합니까? 할 수 없다면이 기능을 구현하는 가장 효과적인 방법은 무엇입니까?AppDelegate에서 프로그래밍 방식으로 App Entry Point 설정

+0

didFinishLaunchingWithOptions 함수에서 선호하는 viewController로 self.window? .rootViewController를 설정하면됩니다. –

답변

3

진입 점이 없는지 고려하십시오. 그런 다음 appDelegate에서 변수를 테스트하고 이에 따라 적절한 스토리 보드를 선택하십시오. 그런 다음 스토리 보드에서보기 컨트롤러를 표시하십시오.

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 

    if globUs.hasName { 
     let storyboard = UIStoryboard(name: "Main", bundle: nil) 
     let vc = storyboard.instantiateViewController(withIdentifier: "FirstMainVC") 
     self.window = UIWindow(frame: UIScreen.main.bounds) 
     self.window?.rootViewController = new 
     self.window?.makeKeyAndVisible() 
    } 
    else { 
     let storyboard = UIStoryboard(name: "NewUser", bundle: nil) 
     let vc = storyboard.instantiateViewController(withIdentifier: "FirstNewUserVC") 
     self.window = UIWindow(frame: UIScreen.main.bounds) 
     self.window?.rootViewController = welcomeVC 
     self.window?.makeKeyAndVisible() 
    } 

    return true 
} 
+0

이 AppDel과 비슷한 방법을 사용하면 SIGABRT가 발생합니다. "NSBundle (로드 됨) ' " UIStoryboard 생성자에서"name : "필드의 의미는 무엇입니까? 그것은 임의적입니까, 아니면 Main.storyboard의 파일 이름을 사용해야합니까? –

+0

감사합니다. –

+0

@GabeSpound 예, 파일 이름을 사용하고 있습니다. – Shades

0

var sb = UIStoryboard(name: "OneStoryboard", bundle: nil) 
/// Load initial view controller 
var vc = sb.instantiateInitialViewController() 
/// Or load with identifier 
var vc = instantiateViewController(withIdentifier: "foobarViewController") 

/// Set root window and make key and visible 
self.window = UIWindow(frame: UIScreen.mainScreen.bounds) 
self.window.rootViewController = vc 
self.window.makeKeyAndVisible() 

을 시도하거나 스토리 보드에서 수동 SEGUE을 시도합니다. 수동 segue를 수행하려면 먼저 스토리 보드에 식별자가있는 segue를 정의한 다음 View Controller에서 performSegue(withIdentifier:sender:)을 호출해야합니다.

+0

위의 답을 위해 남긴 주석을 확인하십시오. 여기에 관련된 내용도 있습니다. –

+0

이 방법이 효과적이지만 다른 방법이 더 효과적입니다. –