views:

13465

answers:

4

Hey all,

I'm new to iPhone development, and multiple views (xib or nib) are really confusing me. This is what i'm trying to achieve...

  1. View with Tab Bar (Tab 1, Tab 2, Tab 3)
  2. Tab 2 View (Navigation Controller) 2.1 Selecting Table Row will show a View with cell details 2.2 Add button on the navigation bar will show a series of view interfaces to get different type of information (e.g. Location Information, Personal Information, etc) - Need this to be sequential, can't use control segment for this. Once information is successfully gathered, create a new cell in Tab 2 View Table, Save related information to a custom structure, and show a completion page with 2 options (Add another, View added item - readonly view)

I'm confused about how to handle these multiple views (both linking them together, and communicating information back and forth). Will all these be handled by my application delegate class or i can/should use multiple delegate classes? Either way can you point me in the right direction - possibly some sample application or tutorial explaining how to handle situation like this or more complex.

Any help in this regard will be highly appreciated.

Thanks, Mustafa

A: 

For the iPhone, you'll want to handle most views and switching between with the the respective view controllers. For your case, these would be the UITabBarController and UINavigationController. For the purposes of controlling them outside the user's own actions and for storing data, as you want, you'll probably need to look into creating your own subclasses of these controllers. Some good starting points would be the TheElements (which covers tab bars and table views) and SeismicXML (table views and navigation controllers).

Most of the actual linking can be handled in Interface Builder, where you can create and layout all the various tabs' contents, but you'll need to use your subclasses to provide data (especially in the case of the table view, where you'll need to setup the data for each cell).

Hope this helped,
Geoff

Arclite
A: 

I have seen both TheElements and SeismicXML examples.

TheElements sample code gives a basic idea of how to use UITabBarController, and UINavigationController, but the example does not discuss passing information from Child Controller to Parent.

In my case, i have a UITabBarController, one of the Tab shows a UINavigationController with (+) on the top right corner or Navigation Bar. Now (+) will open an interface for user input and that input will be used to store the data (say in sql), and create a new Table Cell in UITableView embedded in UINavigationController. Now, the interface that will open using (+) will take user input following a sequence of steps (like Main > Step 1 > Step 2> Complete). Each step will show a separate view. I'm getting hard time trying to design this model. Or, maybe i'm not used to programming in Cocoa/iPhone and i'm not looking straight. What other options do i have - when it comes to taking user input involving 20-30 fields (Text, List, Date, Image e.t.c.). Can you provide some input regarding this.

Thanks for your help, Mustafa

Mustafa
+1  A: 

Perhaps this Google Books link can help you in creation of multiview applications.

I read this entire book. I recommend it for anyone who is trying to learn the iPhone SDK. Though, this is an intro. It doesn't cover all the details...
Frank V
A: 

I think I have a similar problem. I have 3 nibs:

Nib1 --> loads --> Nib2 --> loads --> Nib3

Each nib has its ViewController:

Nib1ViewController, Nib2ViewController, Nib3ViewController

The loading works via:

Nib2ViewController *viewController = [[Nib2ViewController alloc] initWithNibName:@"Nib2" bundle:nil];
[self.view.superview addSubview:viewController.view];
[viewController release];
[self.view removeFromSuperview];

The appdelegate loads Nib1.

I have a button in Nib3.

When clicked, I get an EXC BAD ACCESS error.

Any help?

Up until now, I haven't set up a ViewController icon in the nibs. I created them from XCode via New / UIViewController Subclass with nib so I guessed it was not necessary but now I am going to try that.

Thanks

mga
I finally made it work. Most of the trouble was in the nibs.
mga
Your code sample is incorrect. Instead of attaching the viewController.view to self.view, you should call [self presentModalViewController: viewController animated: YES]; The approach you're using will prevent you from going backwards and removing the views you've loaded.
Ben Gotow
thanks for the reply. Modal views were not applicable for my problem at hand so I did not use that. I ended creating some sort of multi-view framework. More information here: http://www.mauriciogiraldo.com/blog/2009/10/09/multiples-views-no-jerarquicas-en-iphone/
mga
Also, this isn't an answer
SeniorShizzle