【发布时间】:2016-11-15 17:25:36
【问题描述】:
我已经实现了一个 UIPageViewController,它允许用户通过单独的 UITableView 添加/删除/删除新的“页面”,类似于 Apple 在 iPhone 天气应用程序中实现城市/天气位置的方式。项目贴在下面。在这一点上没有天气或花哨的用户界面——我只是想把注意力集中在下面的 UIPageViewController 管理上。如果有人想知道如何使用通过 UITableView 管理的页面来实现 UIPageViewController,希望这很有用: https://github.com/gallaugher/PageViewControllerDemo
它似乎工作正常,但我是新手,我很不确定我是使用推荐的方法还是“Swifty”。
现在我有: PageViewController [初始视图控制器] - 将委托和数据源设置为自己 - 实例化第一个 UIViewController(想象一个用于本地天气的 CityViewController,即使此示例中未添加详细信息和 UI)并设置初始值。 - 城市(天气位置)保存在 [String] 数组中:cityArray
在 CityViewController 中 - 当点击右下角的“Cities”按钮时(在界面构建器中创建),如 Apple Weather,它会打开一个 UITableView (CityListViewController)。
- 为了访问这个 CityListViewController,我触发了直接通过界面生成器从 CityViewController 中的“Cities”按钮绘制到 CityListViewController 的 segue,以模态方式呈现。
- preapareForSegue 将 cityArray 传递给目标 CityListViewController (UITableView)。
在 CityListViewController (UITableView) - 用户可以在 UITableView 更新 tableView & array 中添加城市、移动、删除 - 单击 tableView 行(城市名称或“本地天气”)触发执行 segue,展开到 CityViewController,获取源 CityListViewController 并使用它将数据传回 CityViewController(例如,citiesArray = controller.citiesArray)。 - 这个@IBAction unwind 函数调用PageViewController 的unwind(实际上只是将数据从CityListViewController 中的TableView 传递到UIPageViewController PageViewController)。
在 PageViewController 中展开 - 抓取源(作为 CityViewController) - 传回关键数据(例如,citiesArray = controller.citiesArray) - 调用函数为当前页面实例化视图控制器并设置PageControl索引等
第一季度: 虽然这似乎有效并且我在测试期间没有设法打破它,但从 UITableView 展开到 ViewController 是否是一种合理的方法,它只是触发另一个展开到 UIPageViewController,除了传递数据之外什么都不做?
第二季度: 我已经通过在 PageViewController 中以编程方式构建 UIPageControl 来实现它,但是与 CityListViewController(UITableView)相连接的按钮是使用 Interface Builder 在 CityViewController 中创建的。这是正确的方法吗?我似乎无法在同一个 VC 中创建这两个。
非常感谢那些耐心看完这个复杂的解释的人。仍在尝试处理 VC 之间的数据传递,以及这与 PageControllers 和 TableViews 的关系。
【问题讨论】:
标签: swift uitableview uipageviewcontroller