ios - UIPageViewController subviewcontroller 无法在 viewDidAppear 上执行 segue
问题描述
我有一个包含两个子视图控制器的 UIPageController。开始时,当用户未获得授权时,我试图执行从 SubViewControllerOne 到 LoginViewController 的 segue。我在 viewDidAppear 中有一个 segue,如下所示:
performSegue(withIdentifier: "authorizeSegue", sender: self);
这会产生不成功的 segue 和警告
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)
}
解决方案
Welp,我之前在 tableviews 上通过 didSelect 运行 segues 时遇到过这个问题。解决方案是将其包装在主线程中。不知道为什么这是必要的,但它解决了我的问题。
DispatchQueue.main.async {
self.performSegue(withIdentifier: "authorizeSegue", sender: self);
}
推荐阅读
- java - 我正在尝试公开一个 ArrayList(在 java 中),以便我可以在不同的类中访问它,我做错了什么?
- python - pip install 失败“找不到满足要求的版本”
- sql - 计算客户购买商品的平均价格
- angular - 使用 Injectable service 洞察另一个 Injectable service angular 5
- mysql - msql 将每个类别中的项目计数为 2 列,按状态与连接
- python - 灰度图像到 3 个通道
- android - Kotlin 升级后的顶级声明除外
- angular - 如何过滤和转换 Observable 中的数据 - 重复数据
- c++ - 如何检查两个字符串是否“不管一个字符”是否相等?
- c# - 使用 EnumVisibilityConverter - WPF 从一个用户控件转移到另一个用户控件