ios - 向下钻取,UITableView 和 GridView

标签 ios objective-c uitableview gridview drilldown

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

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

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

问题/问题 1:

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

问题/问题 2:

切换后,如果有其他 Controller 插入导航 Controller , 并且用户返回,这些 View Controller 将在没有任何变化的情况下呈现。我如何更新这些 View Controller ?例如:用户从表切换到网格,然后返回,弹出当前 Controller 后,用户再次看到一个表 -> 错误。

最佳答案

在显示层次结构的顶层(UITableView)的地方,您可能希望在请求时添加 UITableView 或 GridView 作为 subview 。

您将向 View Controller 添加方法:

-(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 中创建这两个,也可以完全通过代码创建,以最适合您的方式为准。关键是,您不会为了重新安排信息的显示方式而将其中任何一个推到导航 Controller 上。

关于ios - 向下钻取,UITableView 和 GridView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14964385/

相关文章:

android - 如何将 Mailchimp 与 Ionic 应用程序集成?

ios - 从 IOS 将图像发送到 asp.net web 服务

ios - 使用 NSURL 而不是 URL 的 dataTask

objective-c - iPhone/iPad double 学

objective-c - NSNotificationCenter 和 Key Value Observing 技术有什么区别?

iPhone - 如何在键盘上方创建一个滚动的 UIToolbar?

iOS Swift float 操作按钮在更改屏幕时移动

ios - 动画 UITableViewCell 高度

objective-c - 执行操作后显示或关闭特定的 ViewController

ios - 显示整个 UIPickerView,然后在选择后隐藏 UIPickerView