Swift - 使用viewDidAppear中的新信息重新加载UIPageViewController

时间:2014-12-06 23:22:57

标签: ios swift reload uipageviewcontroller viewdidappear

如何在viewDidAppear中重新加载UIPageViewController?

在那里,我从CoreData刷新信息,我希望在视图出现时更新值。

我尝试使用函数reloadInputViews(),但仅在您开始打开页面时失败,然后更新信息。

1 个答案:

答案 0 :(得分:5)

如果要在UIPageViewController中重新加载ViewControllers,只需将它们重新设置为:

pageViewController(pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool)

如果要从viewController内部更新viewControllers,则必须以这种方式调用它:

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)
    let viewControllers: [UIViewControllers] = [UIViewController()]
    if let pageViewController = parentViewController as? UIPageViewController {
        pageViewController.setViewControllers(viewControllers, direction: .Forward, animated: true, completion: nil)
    }
}