简体   繁体   English

UIPageViewController如何访问不可见页面

[英]UIPageViewController how to access invisible page

I'm using UIPageViewController to implement infinite horizontal scroll between pages with some data. 我正在使用UIPageViewController来实现具有某些数据的页面之间的无限水平滚动。 Transition type is set to Scroll. 过渡类型设置为“滚动”。

As soon as user starts horizontal scroll I'm giving back detail view controllers for previous and next pages via viewControllerAfterViewController and viewControllerBeforeViewController delegates. 一旦用户开始水平滚动,我就会通过viewControllerAfterViewControllerviewControllerBeforeViewController委托返回上一页和下一页的详细视图控制器。

And at any given time the pageViewController will have a scroll view and three pages inside this scroll view (I can confirm that using Xcode Debug View Hierarchy). 而且在任何给定的时间,pageViewController都会有一个滚动视图和该滚动视图内的三个页面(我可以使用Xcode Debug View Hierarchy确认这一点)。 How do I get access to invisible pages? 如何获得对不可见页面的访问? .viewControllers property contains only one element corresponding to the visible page. .viewControllers属性仅包含一个与可见页面相对应的元素。

The default behavior of the UIPageViewController is to dispose of pages not currently visible. UIPageViewController的默认行为是处理当前不可见的页面。 Its sort of like a UITableView but the cells are view controllers. 它有点像UITableView但是单元格是视图控制器。 The only way to get access to the invisible vcs is to keep strong pointers to them after you build them (probably unwise for an infinite number of pages) or to build a particular one as you need it. 访问不可见的vcs的唯一方法是在构建它们后保留指向它们的强力指针(对于无数页面而言可能是不明智的)或根据需要构建特定的vcs。

That should make you think about what you plan to do with an invisible vc. 那应该使您考虑打算使用不可见的vc做什么。 If you're thinking about changing how it looks, think again: it doesn't exist. 如果您正在考虑更改外观,请重新考虑:它不存在。 Again, this is a little analogous to a UITableView , where we don't usually change cells directly. 再次,这有点类似于UITableView ,我们通常不直接更改单元格。 Instead, we change our model and the cell changes because it is configured in reaction to the model in cellForRowAtIndexPath :. 相反,我们更改了模型,并且单元格也发生了变化,因为它是根据cellForRowAtIndexPath的模型进行配置的。

Same idea here. 同样的想法。 Keep a model around that's independent of the page vcs. 保持模型独立于页面vcs。 When they get viewWillAppear , they can configure their views according to the model. 当他们获得viewWillAppear ,他们可以根据模型配置其视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM