ios - 如何在 ios 中从 appdelegate 呈现不同的 View Controller

标签 ios swift uinavigationcontroller

实际上,我将导航 Controller 作为根 Controller 嵌入到 main.storyboard 中,我有两个屏幕,一个是登录屏幕,另一个是主页,根据登录凭据,我需要跳过登录屏幕,我需要显示主屏幕。来自appdelegate 我正在做这个跳过它不能正常工作

Unbalanced calls to begin/end appearance transitions for <UINavigationController: 0x7fadf384c600>.

 let storyboard=UIStoryboard.init(name: "Main", bundle: nil)
        let navigationController=storyboard.instantiateInitialViewController()
        let username=UserDefaultUtil.getString(key: AppConstants.PREF_USERID)
        print(username!)
        if username != ""
        {
            window?.rootViewController=navigationController
            let sectionController=SectionController(nibName: "SectionController" , bundle: nil)
            navigationController?.present(sectionController, animated: true, completion: nil)
        }

最佳答案

我猜你正试图在 navigationController 中呈现你的 sectionController,它不是真正的工作方式,试试这个代码:

let navigationController = self.storyboard?.instantiateInitialViewController() as! UINavigationController

并用这个替换现在的:

navigationController.setViewControllers([sectionController], animated: false)

或者只是放下 navigationController 实例化并使用代码创建它并将其设置为 window?.rootViewController:

let sectionController=SectionController(nibName: "SectionController" , bundle: nil)
let nav = UINavigationController(rootViewController: sectionController)
window?.rootViewController = nav

关于ios - 如何在 ios 中从 appdelegate 呈现不同的 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40990712/

相关文章:

ios - NavigationLink 与 SwiftUI : Type of expression is ambiguous without more context

iphone - 找不到 momd 文件 : Core Data problems

ios - 从 iPad 应用程序发送 HTML 电子邮件

swift - 插入新单元格时 TableView 更新错误

ios - Swift/popViewControllerAnimated 抛出 nil/如何返回到上一个 viewController?

ios - 导航栏下的模态视图 Controller - Swift

iphone - 不要在 Iphone SDK 的第一个登录页面显示标签栏

iOS SwiftUI : Data Flow Flow in Subviews @ObservedObject

python - 套接字编程 readStream!.takeUnretainedValue() 需要无限时间

swift - 快速向下滑动时的搜索栏