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.
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.
Related
I'm currently using a table view and table view cells in a menu. When you click on one of the cells, it uses a segue inside storyboard to take you to a different view controller depending on which cell you click. They are all different links and the same view controllers except that I change which link opens on which view controller. I know this defeats the purpose of OOP because I'm having individual view controllers do pretty much the same task instead of not having one link opener view controller. How do I get the names of the table cells dynamically in the view controller after a segue?
I have a UITableViewController derived class. In tableView:didSelectRowAtIndexPath:, I create a detail view controller vc and push it with [self.navigationController pushViewController: vc animated: YES];.
On that detail view, I want to be able to swipe left and right and go to the previous/next item detail, or back to the table view if it's on the first/last item. I implemented the swipe and back functionality using [self.navigationController popViewControllerAnimated: YES];, but I'm not sure about how to implement the detail -> detail paging. I thought about using the same pop, then calling tableView:didSelectRowAtIndexPath:, but tracking and modifying the index path and tracking the tableView seems like a clunky way. Is there a better way?
Also, when I pop the view controller, it always slides off to the right. Is there a way to animate it sliding off to the left (to simulate a right to left swipe on the last item)?
The best way to do what you're trying to do is to present your detail contents in a UIPageViewController. It is a collection view controller, kind of like a table view controller. It has a delegate and data source like a table view does. It asks you to give it view controllers that present pages of content. You can set it up to slide from page to page or page curl, and optionally add a book spine. There is a sample app from Apple called PhotoScroller that shows how to set up a page view controller for sliding back and forth. It does a lot more than that, but you can ignore the content view controllers it uses and substitute your own detail view controllers.
You would share the data model between the table view and the page view controller.
I have the task to design a application that has a main view which is always visible (it has a button on it's bottom side, and when pressed a image displays on top of all views), and a set of TableControllerView's that should appear under it, and the user needs to be able to navigate through them.
I know that you can embed a view inside another, but you cannot refer more than one view to it. The current way I'm trying to do now load one TableViewController inside the embed view, and when the user clicks the cell I manually load the other controller and add it as a child of the main view, which is the RootViewController. The problem with this approach is that the navigation bar gets stuck using the root view controller, so I have to manipulate the main navigation items on each subview transition, and second is that the frame for the second view I load is coming as it had full size, making some cells be under the main view button. This way doesn't uses segues for transition, so it makes the storyboard kinda useless.
I was thinking into using a TabViewController with it's tab hidden, but wanted to ask here for a better solution.
As you discovered, a TableViewController likes to fill up the whole screen (except navigation bars, tab bars, status bar, etc. which are official Cocoa Touch GUIs). When you want a table view to fill only part of the screen, you are supposed to use a UITableView but not a UITableViewController. You set your custom view controller object (subclass of UIViewController, not UITableViewController) as the table view delegate and data source. You will need to duplicate part of the functionality of UITableViewController in your custom view controller, but it's not a lot more than you have to do already to supply the data.
You should probably follow the standard design pattern and have separate view controller objects for each of the "pages" the user can navigate to. You just have a main button and image on each of them. But I could imagine why that might not give you exactly the effect you want.
I've followed the CS193p introduction course to objective C. I have now a grouped Table View, and my view controller is a CoreDataTableViewController (from the CS193p class), which is basically just a subclass of UITableViewController with the FetchedResultsControllerDelegate implemented. In my app there are several screens connected, so if you press one row in the first table you get to a new screen with all the subcategories for that main category etc. All the screens are subclasses of this CoreDataViewController.
I'm now confused about how to add a toolbar at the very bottom of a screen in one particular Table View. I guess I have to insert a new view in which I include a table view and a toolbar. What I don't understand how to hookup everything so the whole TableView actually works? Before the very "top" controller was my CoreDataTableViewController (which I've subclassed and implemented my own methods), but now I have no idea how to continue? How do I get the values from the parent view controller to this embedded table view controller and further to his child view controller later on?
If you have a navigation based application you can set up a toolbar by calling:
[self.navigationController setToolbarHidden:NO];
How can I put a segmented control on top of a tableview. I don't want it on the title view of the navigation controller and I don't want it to scroll with the tableview either. For reference of what I mean, please look at App Store app, choose Categories, then select any category. There you will see the segmented control I'm looking for. The one with 'Paid', 'Free', and 'Release Date' segments. I'm using the code not IB, so if you know how please answer this with code not IB drag and drop.
When you need other components in a table view controller other than the table view, you can't use a UITableViewController. You need to use a UIViewController. You add the UITableView as a subview and you make the view controller the table view's data source and delegate. Then you can add any other components to the view controller's view as well. This way the additional components don't scroll with the table view. There's a little more plumbing to do to get the view controller to behave exactly like a table view controller. This includes overriding the setEditing:animated: method to set the editing property of the table view. It includes deselecting any currently selected row in the viewWillAppear: method.
UITableViewController has the table view as its view. This prevents you from adding any other subview to the table view controller in a way that they won't scroll.