Question

I have a UIViewController with an UITableView and a NavigationController to implement a drill down navigation system. The user can browse a hierarchy of folders and documents.

I am using a NSFetchedResultController for populate the UITableView from a data base.

I would like to add the option of browsing the hierarchy using a GridView (fe: AQGridView). The idea is to have a button on the navigation bar for switching between tableView and gridView.

Problem/Question 1:

What is the best way for switching programatically from the controller with a table to the controller with a grid?

Problem/Question 2:

After switching, if there are other controllers pushed into the navigation controller, and the user goes back, these view controllers will be presented without any change. How can I update these view controllers? For example: the user switches from table to grid, then goes back, and after pop the current controller, the user sees again a table -> wrong.

Was it helpful?

Solution

Where you display the top level of the hierarchy (the UITableView), you would want add a UITableView or a the grid view as subviews when requested.

You would add methods to your 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];
}

In the table's data source:

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

You can create both of those either in IB or entirely via code, whichever suits you best. The point is, you would not push either one of those onto the navigation controller just to rearrange how the information is displayed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top