init uipageviewcontroller包含数据

时间:2017-02-05 02:51:09

标签: ios swift

我正在尝试将数据传递到我的UIPageViewController中,因为它依赖于之前的视图,但我正在查看Apple的文档,而且还有

init?(coder:NSCoder)

但我不确定这是否有用。

我想知道是否有办法在实例化时将数据传递给UIPageViewController,以便UIPageViewController填充传入的数据

编辑:只是一个字典,如

["product 1" : "product description",
 "product 2" : "product description",
]

然后传入以填充视图

1 个答案:

答案 0 :(得分:0)

也许这不是你想要的,买你可以通过多种方式在视图控制器之间传递数据。这是其中之一。

因此,在第一个视图控制器中,您可以执行以下操作:

    let SecondViewController = self.storyboard?.instantiateViewController(withIdentifier: "SecondViewController") as! ViewController
    SecondViewController.String = "Some string here"
    SecondViewController.Int = 5
    self.navigationController?.pushViewController(SecondViewController, animated: true)

然后在第二个视图控制器中,您可以通过以下方式接收数据:

    var String:String?
    var Int:Int?

我不确定你是否可以通过这样的整个字典,但我想,它会起作用!所以尝试一下,希望它有所帮助!

另请查看本教程:

相关问题