【问题标题】:VC presenter is not being initialized prepare for segue IOS swiftVC 演示者没有被初始化为 segue IOS swift 做准备
【发布时间】:2022-08-18 20:50:48
【问题描述】:

您好,我正面临问题,因为准备 segue 功能无法正常工作我有代码你能告诉我如何调试它,因为它有可选条件我如何删除它们并检查问题或者我做错了什么,因为我只想在应用程序导航到其他屏幕之前在目标 vc 中初始化一个类。

@IBAction func filterBtnPressed(_ sender: Any) {
    
    self.performSegue(withIdentifier: \"FilterSessionVC\", sender: self)
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == \"FilterSessionVC\", let navigation = segue.destination as? UINavigationController, let vc = navigation.topViewController as? FilterSessionVC {
            vc.presenter = FilterSessionPresenterImplementation()
        }
    }
  • 我建议您不要使用故事板并开始以编程方式制作应用程序。

标签: ios swift xcode segue iosdeployment


【解决方案1】:

基本调试...

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    
    let identifier = segue.identifier
    print("identifier:", identifier)
    
    let dest = segue.destination
    print("destination:", dest)
    
    if let navigation = dest as? UINavigationController {
        print("dest IS a UINavigationController")
        
        if let vc = navigation.topViewController as? FilterSessionVC {
            print("Top Controller IS a FilterSessionVC")
            // here you can proceed
            vc.presenter = FilterSessionPresenterImplementation()
        } else {
            print("Top Controller IS NOT a FilterSessionVC")
        }
        
    } else {
        print("dest IS NOT a UINavigationController")
    }
    
}

在第一行设置断点,然后单步执行并检查结果。

【讨论】:

    猜你喜欢
    • 2014-07-25
    • 2017-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多