我在PageViewController
中创建了ViewController
,您可以看到下一个:
MainViewController(viewDidLoad())
self.pageViewController = UIPageViewController(transitionStyle: .Scroll, navigationOrientation: .Horizontal, options: nil)
self.pageViewController.dataSource = self
self.pageViewController.delegate = self;
self.pageViewController.view.frame = CGRectMake(0, 100, self.view.frame.size.width, self.view.frame.size.height)
let initialViewController : UIViewController! = viewControllerArray.objectAtIndex(self.currentPageIndex) as! UIViewController
let viewControllers: NSArray? = NSArray(objects: initialViewController)
pageViewController.setViewControllers(viewControllers as? [UIViewController], direction: .Forward, animated:true, completion: nil)
self.addChildViewController(self.pageViewController)
self.view.addSubview(self.pageViewController.view)
self.pageViewController.didMoveToParentViewController(self)
self.syncScrollView()
一切都很好。此viewController
捕获方法
func presentationCountForPageViewController(pageViewController: UIPageViewController) -> Int
我的问题是这个pageViewController的其中一个页面里面有其他UIPageViewController,其他的UIViewController是关联的。我创建其他UIPageViewController的方式是:
SecondViewController(viewDidLoad()
)
self.pageNoticiaViewcontroller = UIPageViewController(transitionStyle: .Scroll, navigationOrientation: .Vertical, options: nil)
self.pageNoticiaViewcontroller.didMoveToParentViewController(self);
self.pageNoticiaViewcontroller.dataSource = self;
self.pageNoticiaViewcontroller.delegate = self;
let startVC = self.getControllerAtIndex(0) as InicioIndividualUIViewController;
let viewControllers = NSArray(object: startVC);
self.pageNoticiaViewcontroller.setViewControllers(viewControllers as? [UIViewController], direction: .Forward, animated: true, completion: nil);
self.pageNoticiaViewcontroller.view.frame = CGRectMake(0, 0, self.view.frame.width, self.view.frame.height - 40);
self.addChildViewController(self.pageNoticiaViewcontroller);
self.view.addSubview(self.pageNoticiaViewcontroller.view);
问题是:
第二个PageViewController(pageNoticiaViewController
)不会调用方法presentationCountForPageViewController
,但会调用方法presentationCountForPageViewController
父
如何对第二个UIViewController的方法PageViewController
进行第二次presentationConuntForPageViewController
调用,而不是调用父方法?非常感谢你!
答案 0 :(得分:3)
我想你必须尝试这样:
self.pageViewController.view.tag=0
self.pageNoticiaViewcontroller.view.tag=1
并将条件放在datasource和委托方法中,如
示例:
func presentationCountForPageViewController(pageViewController: UIPageViewController) -> Int
{
if pageController.view.tag == 0
{
return yourcount // here self.pageViewController count
}
else
{
return yourcount // here self.pageNoticiaViewcontroller count
}
}