我想创建一个入职/注册序列。为此,我尝试使用带有标题和进度条以及页面视图的场景。在该页面视图中,注册序列和入门的每个部分将是多个场景。用户可以浏览它们,它将更新进度条,显示它们到底有多接近。
如何使用"创建帐户"从区域的视图控制器访问子项(RegistrationPageViewController)中的进度条。标题?
答案 0 :(得分:1)
最好的方法是实施 UIContainerView 。它将自动添加为您的父UIViewController作为childviewcontroller。可以使用self.childViewControllers
访问ContainerView。
for each in self.childViewControllers
{
if let containerView = each as? <YourContainerView_ViewControllerClass>
{
//manage containerView objects here
}
}
也可以重用这个UIContainerView。
答案 1 :(得分:0)
处理此问题的更好方法是使用委托,因为子视图控制器无权访问父级。
class ParentViewController: UIViewController {
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "pageViewController" {
let dest = segue.destination as? UIPageViewController
dest?.delegate = self
}
}
}
extension ParentViewController: UIPageViewControllerDelegate {
func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
//set progress bar by analyzing pageViewController.viewControllers to see which page you're on.
}
}