【问题标题】:UIPageViewController subviewcontroller can't perform segue on viewDidAppearUIPageViewController subviewcontroller 无法在 viewDidAppear 上执行 segue
【发布时间】:2020-02-14 07:34:32
【问题描述】:

我有一个 UIPageController,其中包含两个子视图控制器。开始时,当用户未获得授权时,我试图执行从 SubViewControllerOne 到 LoginViewController 的 segue。我在 viewDidAppear 中有一个 segue,如下所示:

performSegue(withIdentifier: "authorizeSegue", sender: self);

这会产生不成功的转场和警告

Warning: Attempt to present <Volley.LoginViewController: 0x7f98bd801e00> on <Volley.SubViewControllerOne: 0x7f98bd608400> whose view is not in the window hierarchy!

我在过去使用 ViewControllers 和 TabBarViewControllers 成功地做到了这一点。

当我将 segue 包装在计时器中或通过 IBAction 触发时,segue 工作得非常好。我相信它与 PageViewController 有关。

class PageViewController: UIPageViewController, UIPageViewControllerDataSource, UIPageViewControllerDelegate, UIScrollViewDelegate {

    var subViewControllers = [UIViewController]()

    override func viewDidLoad() {
        super.viewDidLoad()
        self.delegate = self
        self.dataSource = self
        self.edgesForExtendedLayout = [];
        // Do any additional setup after loading the view.

        let subViewControllerOne = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "SubViewControllerOne") as! SubViewControllerOne
        let subViewControllerTwo = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "SubViewControllerTwo") as! SubViewControllerTwo
        subViewControllers = [yourPodcastViewController, appearancesViewController]
        setViewControllers([subViewControllers[0]], direction: .forward, animated: true, completion: nil)
    }

    required init?(coder: NSCoder) {
        super.init(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil)
    }

导航控制器和PageViewController

从 SubViewControllerOne 到 LoginViewController 的转场

【问题讨论】:

    标签: ios swift xcode segue


    【解决方案1】:

    我认为由于视图控制器生命周期,您应该执行 segue 到 viewWillApear

    【讨论】:

      【解决方案2】:

      Welp,我之前在 tableviews 上通过 didSelect 运行 segues 时遇到过这个问题。解决方案是将其包装在主线程中。不知道为什么这是必要的,但它解决了我的问题。

      DispatchQueue.main.async {
        self.performSegue(withIdentifier: "authorizeSegue", sender: self);
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-01-03
        • 1970-01-01
        • 2023-03-14
        • 1970-01-01
        相关资源
        最近更新 更多