动态更新 UIPageViewControllerDataSource 数据

Dynamically update UIPageViewControllerDataSource Data

我使用基于页面的应用程序模板创建了简单的应用程序。所有数据都存储在 var pageData = NSArray() 中,在 Apple 的示例中,它在 ModelController class 的 init 方法中初始化。现在我需要用从服务器接收到的数据更新页面。我在 ModelController class 中创建了方法 updateDataFromServer,其中将 json 请求发送到服务器并更新 pageData。如果我试图从 ModelControllerinit 调用我的 updateDataFromServer,一切都会出错。我应该从哪个地方调用 updateDataFromServer 以及如何正确更新 pageData?也许 func updateDataFromServer 应该放在其他地方?

源代码:http://github.com/stillfinder/UAH-Rate

您可以将您的方法放在 RootViewController 中,它可能是 UIViewController 的 class,您可以将您的方法放在 class 中,然后从 viewDidAppear.

只要您的方法从服务器获得响应,您就可以在 rootview 本身中重新加载数据源,并将该数组复制到 modelViewController,以便 PaginationViewController - 数据源得到更新。

您可以post您的代码以获得更多帮助。

希望对您有所帮助。

HTH,享受编码吧!