0

내 앱이 firebase에 요청을하고 요청이 완료되면 루트보기를 다시 지정하는 동안 시작 화면을 루트보기로 설정했습니다. 불행히도이 작업을 수행하면 내 탐색 막대가 사라지거나 새 루트보기로 덮여 있습니다. 시뮬레이터를 실행할 때 내비게이션 막대를 잠시 본 다음 내 TableViewController에 의해 가려집니다. 어떻게 이런 일이 일어나지 않게해야합니까? 나는이 일을 모두 할 경우탐색 모음이 사라짐 루트 ViewController가 변경된 다음 다시 할당 됨

다음은 AppDelegate에에서 내 코드입니다 :

var window: UIWindow? 
let searchManager = SearchManager() 

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 
    makeRootViewLaunchScreen() 
    FirebaseApp.configure() 
    searchManager.getMosaicTitles { results in 
     self.searchManager.listOfMosaics = results 
     self.stopDisplayingLaunchScreen() 
    } 
    // Adds border to bottom of the nav bar 
    UINavigationBar.appearance().shadowImage = UIImage.imageWithColor(color: UIColor(red:0.00, green:0.87, blue:0.39, alpha:1.0)) 
    // Override point for customization after application launch. 
    return true 
} 

func makeRootViewLaunchScreen() { 
    let mainStoryboard: UIStoryboard = UIStoryboard(name: "LaunchScreen", bundle: nil) 
    let viewController = mainStoryboard.instantiateViewController(withIdentifier: "launchScreen") 
    UIApplication.shared.keyWindow?.rootViewController = viewController 
} 

func stopDisplayingLaunchScreen() { 
    let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil) 
    let viewController = mainStoryboard.instantiateViewController(withIdentifier: "centralViewController") as? SearchResultsTableViewController 
    viewController?.searchManager = searchManager 
    UIApplication.shared.keyWindow?.rootViewController = viewController 
    UIApplication.shared.keyWindow?.rootViewController?.navigationController?.isNavigationBarHidden = false 
} 

당신은 내가 나타날 때까지 탐색 모음을 강제로 UIApplication.shared.keyWindow?.rootViewController?.navigationController?.isNavigationBarHidden = false를 사용하려고 볼 수 있듯이하지만 그렇지 않습니다. 내 응용 프로그램은 여전히 ​​다음과 같습니다. what it looks like with missing navigation bar

답변

1

루트 컨트롤러로 UIViewController을 설정하고 있습니다. 원하는 것은 UINavigationController을 루트 컨트롤러로 설정하는 것입니다.

어느 스토리 보드에 새로운 탐색 컨트롤러를 만들고로드로드하는 대신 하나 "centralViewController을"또는 수정 함수를 다음과 같이 :

func stopDisplayingLaunchScreen() { 
    let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil) 

    if let viewController = mainStoryboard.instantiateViewController(withIdentifier: "centralViewController") as? SearchResultsTableViewController { 

     viewController.searchManager = searchManager 

     // create a new UINavigationController 
     let newNavVC = UINavigationController() 

     // set the "root" VC of the NavVC to your SearchResultsTableViewController 
     newNavVC.setViewControllers([viewController], animated: false) 

     // use the new NavVC as the new rootViewController 
     UIApplication.shared.keyWindow?.rootViewController = newNavVC 
     UIApplication.shared.keyWindow?.rootViewController?.navigationController?.isNavigationBarHidden = false 

    } 
} 

참고 : 테스트하지, 그러나 이것은 당신을 얻어야한다 당신의 방법.

편집 : 또 다른 방법 ... 키 윈도우의 루트 컨트롤러를 교환, 당신은 당신의 데이터를 검색/초기화하는 나타내는의 ViewController를 만드는 대신에

. 그 VC는 네비게이션 컨트롤러의 "루트"가 될 수 있습니다.

귀하의 searchManager.getMosaicTitles 기능을 에 넣으십시오. VC. 완료되면 은 Nav Controller의 현재 "시작"컨트롤러 인을 TableVC로 바꿉니다.

// note: searchManager will have to be a reference back to AppDelegate.searchManager 
searchManager.getMosaicTitles { results in 
    self.searchManager.listOfMosaics = results 

    let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil) 

    if let viewController = mainStoryboard.instantiateViewController(withIdentifier: "centralViewController") as? SearchResultsTableViewController { 

     viewController.searchManager = searchManager 

     // replace the current Nav VC stack with the new SearchResultsTableViewController 
     self.navigationController.setViewControllers([viewController], animated: false) 

    } 
} 
+0

위의 코드를 사용하여 시뮬레이터에서 실행하면 간단한 내비게이션 막대가 보이고 새 탐색 막대가 표시됩니다. 어떻게 수정해야합니까? 이전 탐색 컨트롤러를 삭제합니까? –

+0

확실하지 않습니다 ... 만약 당신이라면,'.keyWindow? .rootViewController' 대신에 현재 탐색 컨트롤러의 현재 View Controller를 바꿀 것입니다. – DonMag

+0

네비게이션 막대가로드되는 성가신 지연이 있습니다. 사용자에게 tableview가 표시됩니다. –