无法实例化视图控制器Swift

问题描述 投票:0回答:1

我的代码到目前为止运作良好。我没有看到我可以改变什么来使它像那样的bug。当我想将用户返回到主页时,它可以工作,但是在前一个ViewController重新出现在屏幕上几秒钟之后。

我试图用“as UIViewController”或者作为NavigationViewController来改变“as!HomeViewController”,但它继续前往ViewController。

    let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
    let balanceViewController = storyBoard.instantiateViewController(withIdentifier: "home") as! HomeViewController
    self.present(balanceViewController, animated: true, completion: nil)
swift navigation viewcontroller
1个回答
0
投票

当我想将用户返回主页时......

你应该使用UINavigationController.popToViewController(_:animated:)返回UIViewController

let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let balanceViewController = storyBoard.instantiateViewController(withIdentifier: "home") as! HomeViewController
self.navigationController?.popToViewController(balanceViewController, animated: true)
© www.soinside.com 2019 - 2024. All rights reserved.