2017-04-18 4 views
0

사용자가 로그인되어 있는지 여부에 따라 루트보기 컨트롤러를 응용 프로그램 대리자의 didFinishLaunchingWithOptions에서 변경하려고합니다. 나는이 조건을지나 일단, 나는 루트 뷰 컨트롤러를 변경하려면 다음 코드를 사용하고 있습니다 :AppDelegate에서 루트보기 컨트롤러를 변경할 때 검은 화면이 나타남

self.window = UIWindow(frame: UIScreen.main.bounds) 
self.window?.rootViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "SWRevealViewController") as! SWRevealViewController 

self.window?.makeKeyAndVisible() 

을하지만, 내가 (사용자의 유효한 로깅과) 응용 프로그램을 시작할 때 시뮬레이터가 첫 번째 화면에서 로그를 (보여줍니다 오래된 루트보기 컨트롤러)를 잠깐 동안 누르면 화면이 약 30 초에서 1 초 동안 검게 변하면서 마침내 원하는보기 컨트롤러가 표시됩니다.

은 다음 스토리 보드의 뷰 컨트롤러의 구조가 될 때 :

SWRevealViewController -> 탐색 컨트롤러 ->보기 컨트롤러 (새로운 루트) SWRevealViewController로 시작을위한

이유는 슬라이드 메뉴 그렇지 않으면 손실되어 원하는 때문에 .

어떤 일이 벌어지고 있는지에 대한 아이디어가 있습니까?

+0

윈도우 키를 만들고 표시하기 전에'rootViewController' *를 설정할 수 있습니까? – NRitH

+0

@NRitH 결과는 완전히 동일합니다. – rodrigochousal

+0

코드를 좀 더 보여줄 수 있습니까? loginViewController를 설정하는 방법과 표시된 코드를 트리거하는 방법을 확인하는 것이 유용 할 것입니다. –

답변

0

여기 나와있는 예제가 있는데, loginViewControllersSWRevealController과 관련이없는 UINavigationController의 스택으로 설정하면됩니다. 쉬운 해결 방법입니다.

self.window = UIWindow(frame: UIScreen.main.bounds) 
if User.shared.firstLaunch { 
    let navigationVC = Storyboard.inital.instantiateViewController(withIdentifier: "firstLaunchNC") as! UINavigationController 
    self.window?.rootViewController = navigationVC 
} else if User.shared.token == "" { 
    let navigationVC = Storyboard.inital.instantiateViewController(withIdentifier: "initialVC") as! UINavigationController 
    self.window?.rootViewController = navigationVC 
} else { 
    self.registerForPushNotifications(application: UIApplication.shared) 
    User.shared.refreshToken() 
    let revealController = Storyboard.main.instantiateViewController(withIdentifier: "revealViewController") as! SWRevealViewController 
    self.window?.rootViewController = revealController 
} 

self.window?.makeKeyAndVisible() 
return true 
0

내가 원하는 것과 비슷한 결과를 산출하는 방법을 찾았습니다. 그것은 모든 루트 뷰 컨트롤러를 변경하고, 발사 후 "인공 루트 뷰 컨트롤러"를 제시 있지 않는 포함 :

if let currentRoot = self.window?.rootViewController { 
    let storyboard = UIStoryboard(name: "Main", bundle: nil) 
    let artificialRoot = storyboard.instantiateViewController(withIdentifier: "SWRevealViewController") 
    currentRoot.present(artificialRoot, animated: false, completion: nil) 
} 

적합하지 않지만,이 구현의 결과는의 구현보다 훨씬 더 나은에 의해입니다 질문 설명.