【问题标题】:how to open UIPageViewController on button click如何在按钮单击时打开 UIPageViewController
【发布时间】:2019-01-26 13:05:12
【问题描述】:

看起来是重复的吧??

但是我在网上搜索,我什么也没找到..

请有人帮助我如何在按钮单击时打开 UIPageViewController

如果我们想打开 uiviewcontroller 我们可以使用它

let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)

let nextViewController =     storyBoard.instantiateViewControllerWithIdentifier("nextView") as NextViewController
 self.presentViewController(nextViewController, animated:true, completion:nil)

但是 UiPageViewController 呢??

如何做到这一点?

【问题讨论】:

  • 我认为如果 NextViewController 是 UIPageViewController 应该可以工作,错误是什么?
  • 如果有重要的数据需要传递来填充pageViewController,你需要:let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil) let nextViewController = storyBoard.instantiateViewControllerWithIdentifier("nextView") as NextViewController NextViewController.importantDataVariable = ImportantData self.presentViewController(nextViewController, animated:true, completion:nil)才能在不崩溃的情况下打开它。

标签: ios swift uipageviewcontroller


【解决方案1】:

您可以使用故事板转场。确保您的初始 VC 嵌入在 NavigationController 中。然后创建一个从初始到你的 pageViewController 的 segue 并给它一个 ID。

接下来,在您的初始视图控制器代码中,执行推送而不是实例化。

self.performSegue(withIdentifier: "seguetoPVC", sender: self)

把它放在你的按钮点击中,它会允许你在按钮点击时打开你的 PageViewController。希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-14
    • 1970-01-01
    • 2012-02-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多