gpt4 book ai didi

swift - PageViewController 嵌入在其他 PageViewController 中

转载 作者:行者123 更新时间:2023-11-28 11:10:57 24 4
gpt4 key购买 nike

我在 ViewController 中创建了一个 PageViewController,如下所示:

主视图 Controller (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 的方法 presentationConuntForPageViewController 进行第二次 PageViewController 调用,而不是对父方法的调用?非常感谢!

最佳答案

我认为你必须这样尝试:

self.pageViewController.view.tag=0 

self.pageNoticiaViewcontroller.view.tag=1

并将条件放入数据源和委托(delegate)方法中,如

例子:

 func presentationCountForPageViewController(pageViewController: UIPageViewController) -> Int
{

if pageController.view.tag == 0
{
return yourcount // here self.pageViewController count
}
else
{
return yourcount // here self.pageNoticiaViewcontroller count
}
}

关于swift - PageViewController 嵌入在其他 PageViewController 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35115555/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com