1

我有一个带有 UITableView 和 NavigationController 的 UIViewController 来实现向下钻取导航系统。用户可以浏览文件夹和文档的层次结构。

我正在使用 NSFetchedResultController 从数据库中填充 UITableView。

我想添加使用 GridView (fe: AQGridView) 浏览层次结构的选项。这个想法是在导航栏上有一个按钮,用于在 tableView 和 gridView 之间切换。

问题/问题1:

以编程方式从带有表格的控制器切换到带有网格的控制器的最佳方式是什么?

问题/问题2:

切换后,如果导航控制器中还有其他控制器被推入,用户返回,这些视图控制器将原封不动地呈现出来。如何更新这些视图控制器?例如:用户从表格切换到网格,然后返回,弹出当前控制器后,用户再次看到表格 -> 错误。

4

1 回答 1

2

在显示层次结构的顶层(UITableView)的地方,您需要在请求时添加 UITableView 或网格视图作为子视图。

您将向视图控制器添加方法:

-(void)displayAsGridView {
    // hide/remove the table view
    // populate the grid view and display
}

-(void)displayAsTableView {
    // remove or hide grid view
    // make sure the table view exists, if not, create it
    [self.tableView reloadData];
}

在表的数据源中:

-(UITableViewCell*)tableView:(UITaleView*)tableView cellForRowAtIndexPath:(IndexPath*)indexPath {
    // you populate the view cell as you would for any other table
}

您可以在 IB 中或完全通过代码创建这两者,以最适合您的方式创建。关键是,您不会将其中任何一个推送到导航控制器上,只是为了重新安排信息的显示方式。

于 2013-02-19T18:31:34.670 回答