Iphone UiNavigation controller types - iphone

In examples I have seen of UINavigationContoller and UITableView, switching to next view is usually triggered by tapping into that cell and pushing a different UIViewController on top of stack, but what I want is to switch to next view by pressing a next button in bottom of page, which I want it to load the same UITableViewController again but with different contents in each cell.
-Can I put that next button on bottom of page? and where
-Can I call the same controller (but showing different contents) and put on top of stack using the UINavigationController?
Because I want to be able to browse back previos pages.

You would generally do as you highlighted first and push a new UIViewController subclass onto the UINavigationController.
A UIViewController is supposed to manage one screens worth of content. If you plan on breaking that convention by presenting different information you are essentially going to have duplicated if statements to decide whether the user should be viewing the content from before or after the button was tapped.
UINavigationController's are good for hierarchal data where the content becomes more specific as you drill down. The UINavigationController will also manage the stack so that you can go to previous pages.
To achieve what you want to achieve (stated here) you should be using a UINavigationController with your custom subclass of UITableViewController when the user submits questions you receive your xml, parse it and then instantiate a new instance of your UITableViewController subclass and push it onto the stack.

You can add a button in the footer view of your table view. To achieve this have a look at tableView:viewForFooterInSection:. Then add an action to that button which allocs and inits the view controller with the new content and pushes it onto the stack.

Just make your UITableViewDatasource returning your number of rows plus one in the last section you have in –(NSUInteger)tableView:numberOfRowsInSection:. Set any content for that cell before returning it to the tableView.
Then only push a new UIVIewController, when the user touches that last cell.
You could also make the delegate of the UITableView returning nil on :
-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath for the cells you don't want the user select.

Related

Using Storyboard, UISplitViewController and multiple detail views (MultipleDetailViews with storyboard)

All,
It's not this: Science At Hand - Adventures in UISplitViewController. That really goes from the UITabBarController rather than the cells in the Master.
Let's say I want to create a SplitViewController. On the left side I have different types of cells in the same list (It's not going on Apple Store, so I don't care if it's Apple iOk or not). For each of the different cell types I want to have a different DetailView controller. Cell Type A shows DetailView A, Cell Type B shows DetailView B.
How do I update the SplitViewController subviews to shift detailviews?
Can I just put the navigation controller under the detail and then add viewControllers to that? Using the get based on seque name or get view from storyboard?
Some other, really obvious way that I'm just missing.
For bonus points, I would like a way to detect that I'm leaving one detailview (for saving) and moving to a different detailview (A different cell type button was pressed)
It turns out it was simple.
If you do the obvious (who would have thought?) it works just fine. I created my different cellviews. Each cell view has details link that I just linked to a series of view controllers. I just had to change the seque so that it was a replace and it put the view into the detail view.
I'm make this sample in GitHub
https://github.com/AlfonsoMoreno/MultipleDetailView
MasterViewController is UITableViewController
FirstDetailViewController is UIViewController
SecondDetailViewController is UITableViewController
You can add more views!!!
Please watch MultipleDetailViewManager class!!!

2 UITableViewControllers vs 1 UIViewController that swaps two UITableViews

I have a navigation controller that works with two UITableViewControllers. The first UITableViewController shows the user a list of their picture libraries, and when they tap a cell, the second UITableViewController gets pushed on the stack and displays the pictures in the library (much like a UIImagePicker). What I want to do is, when a user selects a photo library on the initial UITableViewController, I want the navigation title to not animate, while the transition of UITableViews does animate. Is there a way to accomplish this, or do I need to implement a UIViewController that swaps in two UITableViews (upon then I'm not sure if I'd be able to edit the back button after the second UITableView gets swapped in?).
I'm pretty sure that the easiest way would be to add two UITableViews into a UINavigationController's view and just animate them with [UIView beginAnimation] in a didselectrowatindexpath. You should also have a flag to save a view state - either a library picker view is shown to user or an image picker. Then you'll be able to handle this properly in a back button selector.
That's the easiest way IMO.
I'd recommend one UIViewController and animating the frames of the table views to transition between them.

Tab-Bar with Table-Views - like iTunes/Music app!

I'm trying to replicate the functionality of the Music App (the one that comes built-in to all our iPhones/iPods.)
My goal is to have:
1) a Tab-Bar controller at the bottom, where every tab click loads a TableView.
2) Need to make sure that the Tab-Bar never disappears when these various table-views are loaded
3) the Table-Views must enable user to drill-down further and further into other table-views, sometimes 3 or 4 levels deep - but the tab-bar should never go away
4) One last thing: if possible, all the loaded Table-Views should NOT be Navigation Controllers, but regular UIViewControllers that then contain Tables (this is because it doesn't seem possible to resize tables when they're created as "UITableViewController"s, only when they're embedded into regular UIViewControllers, as-in, dragged and dropped out of the Objects Library onto an existing view.)
Anybody out there go some sort of tutorial or even code-template/engine type thing that they can share with us on how to do this?
As far as i understand, you know that it is possible to use UINavigationControllers as UITabBarController's controllers. What is the reason then not to use the navigation controllers ?
That must be completely what you want to do: create tables in the code or link it as the outlets with Interface Builder as you can either use UIViewController or UITableViewController (which inherits from UIViewController) as root and popped to stack of NavController.
Assuming you use XCode 4 here is the link to tutorial
upd:
for the header and footer views it is always better to use UITableView object's tableHeaderView and tableFooterView properties. Then you do not need to calculate the margins and update the view layout manually as it comes automatically.
Regarding the navigation, it is a general practice to set the controller containing the table to be the table delegate itself and then to use the method
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
when you select one of the table cells, that method is called and you can create an instance of the next view controller, preconfigure it and then push to navigation stack. Back button comes automatically - and you are done. If you have the table in the next navigation controller, be careful while copy-pasting the methods from the previous-one, i.e. if you have wrang number of rows at
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
your application will crash.

how to manage a stack of UITableViews without a navigation controller

I am new to iPhone development, and I am working on modifications to an existing iPhone app. The high-level overview of the issue is this.
I have a button displaying a pop-up containing a UITableView.
I'd like to click on a menu item and display a second UITableView with sub-items, including a back option. If the user clicks back, they go the original UITableView. If the sub-item has additional sub-items underneath it, it should (when clicked) launch another UITableView with these options. There is also a back button as a menu item that will allow the user to navigate to the previous menu displayed.
The challenge here is that I am not using a navigation controller. the original developer only wants to add UITable Views to the stack, add transitions between them as you go from one menu to the other. Most of the tutorials I have seen and tried utilize a navigation controller and Interface Builder to associate the UITableViews.
Right now, I have an XML data source populating the menu, and when I click on a menu item, the titles change correctly, but still uses the same UITableView to display the options - this has consequences of course, as some of the sub-items may not fit on a screen.
any thoughts on how this can be done? I can post some code if necessary, although I think the general description should be able to ring a bell with one of you smart guys!
This can be done in numerous ways.
I haven't done this first one, but you can probably create a UINavigationController and set its view to the appropriate frame (inside the bubble) hide the navigation bar and set the action of your back button to pop the current view controller.
Another method is to have multiple tableviews on one controller, the delegate and datasource methods have the UITableView as an argument so you can distinguish them when setting the height of your rows, headers etc and when returning a UITableViewCell.
The way I've chosen to deal with such configurations is to have one UITableView and have only the datasource change. When you reload, insert, delete rows or reload the whole table, you can change anything you want depending on the current datasource level. The easiest none animated way is to reload the whole table.
a) If your "options" go off-screen height wise (you want fixed height) table change the - (CGFloat)tableview:(UITableView *)table heightForRowAtSection:(NSInteger)section return value
b) If your "options" go off-screen length wise either make your cell's default textLabel flexible: cell.textLabel.adjustsFontSizeToFitWidth = YES; cell.textLabel.minimumFontSize = 14; or have custom cells (lookup subclassing UITableViewCell, which is recommended) for each datasource level.
If you subclass TableViewCells remember to have different dequeue cell identifiers for each level, so the table doesn't provide you with another level's cell class.
For the "stack" of tableviews or datasources, you can have an NSMutableArray with addObject for push and removeLastObject for pop.
For animations, UITableViews can animate their rows/sections for 3. (see documentation for insert, delete, reload - Rows/Sections UITableView class reference), for 2. you can even have UIView (if not CoreAnimation as Grimless suggested) animations, that move the current tableview to the left (setFrame:) and the next tableview from the right (setFrame offscreen before animation and then in place in the beginAnimation-commitAnimation clause), but make sure you add the tableviews in a container view (the bubble interior) that clips its subviews.
Oi. This is gonna be a tough one. My suggestion would be to maintain your own stack implementation. Then, use CoreAnimation to add/remove UITableViews from your main view controller to get animated effects. So whenever the user clicks on an element in the current table view, the appropriate controller creates a new controller and table view, and then your custom navigation controller pushes the old one onto the stack, removes the old table view from the main view, sets the new controller as the current one, and adds the new table view to the main view. Kinda messy, but I think it will work.

Having UITableView edit button outside of the navigation bar

I have a UIViewController, and within that view i have UITableView added in IB
The UITableView displays the items from my array beautifully
I would like to be able to edit the items i.e delete them
BUT The UITableView does not have a navigation bar, and i am not using a navigation controller within this app i am just adding and removing views manually.
What i would like to do is place an "edit" button somewhere else within the view ... is this possible? and how might i go about this?
Put a button somewhere. In an action connected to it set TableView's editing property to YES - it should work fine. You also need to implement delegate's editingStyleForRowAtIndexPath method (return UITableViewCellEditingStyleDelete to allow to delete cells).
You could make one special cell (e.g. 1st row, 1st group) a button by implementing a adaequate didSelectRowAtIndexPath.
Or you could put buttons for editing/deleting in each cell (if single deletion/editing makes sense).
Or you could place the UIIableView on a super view wich also contains the button(s) as sub views.