【问题标题】:How can I add a new Page on UIPageViewController?如何在 UIPageViewController 上添加新页面?
【发布时间】:2015-09-10 16:35:03
【问题描述】:

我刚刚创建了一个新的 Xcode 项目作为基于页面的应用程序,我想添加一个新按钮,该按钮将在运行时创建一个新页面。我该怎么做?

实际上,一个名为“Dwindle”的应用程序有它。它是免费下载的,只是说如果有人想知道我在说什么。

感谢您的帮助。

【问题讨论】:

  • 如果那个应用有这个功能,你为什么不直接复制它呢?

标签: ios swift uikit


【解决方案1】:

这是可以实现的。 UIPageViewController 通过委托方法 - presentationCountForPageViewController: 计算它拥有的页面数。 您可以在类中添加一个属性,例如:

@property int total;

您可以通过这种方式从委托方法中返回属性值。

- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController {
    // The number of items reflected in the page indicator.
    return self.total;
}

每当发生事件时(您提到的 Ex 按钮单击)- 您可以增加属性的值 - total 并使用方法 - setViewControllers: 重新渲染 pageViewController。

[self.pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];

这将使用新值 total 重新加载 pageViewController。

【讨论】:

  • 为什么不能使用数组 viewControllers 的计数来知道你有多少页?那不一样吗?
猜你喜欢
  • 2013-02-25
  • 1970-01-01
  • 2011-12-29
  • 1970-01-01
  • 2019-02-10
  • 2021-12-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多