Reputation: 1101
I am getting started with iphone development and am trying to move from one view to another.
I have a main view (NearestPhotosViewController) which basically acts as a menu for my app. I then have a second view (DisplayNearestPhotos).
I come from a web (html) background so what i'm trying to do here in web terms is click a button (link) on the NearestPhotosViewController view to then display the DisplayNearestPhotos view.
I have been looking around for some code to do this (I don't think it's as simple as doing the equivelent in html).
The following code is hooked up to a button on my menu view.
-(IBAction)ButtonPressed:(id)sender
{
DisplayNearestPhotos *views = [[DisplayNearestPhotos alloc]
initWithNibName:nil bundle:nil];
[self presentModalViewController:views animated:YES];
views.release;
}
The above code works (it displays the second view) but what i'd like to know is, is that the correct way to do it? If not, what is the correct way to move from one view to another?
Thank you in advance
Upvotes: 0
Views: 4736
Reputation: 597
It depends on your design. If your application has proper screen flows, UINavigationController is good option. Using this, you can navigate to other screens on button click. UINavigationController itself maintains stack of the screens and provides a back button to navigate to previous screen. Hence it is easy to maintain a screen flow. If your design have screens apart from normal screen flow, you can use a modal-View controller to present the screen. This will not interfere i the screen flow. for e.g. if your application has a root screen and you want to display an information screen, you can present the information screen using modal view controller. The method you use will affect the screen animation. Modal view controller will present the screen from bottom while navigation will present the screen from right to left. If you want to display different screens on tab bar click, you use UITabBarController. Also you can use combination of all the types mentioned in your application.
Upvotes: 1
Reputation: 13137
The way I got started with iPhone development was with the three20 project. If you look at the sample app, TTCatalog
, you'll see an interesting pattern they came up with that should appeal to people with web development backgrounds.
They set up a mapping of "urls" to classes (in this case, view controllers) like this:
TTURLMap* map = navigator.URLMap;
[map from:@"*" toViewController:[TTWebController class]];
[map from:@"tt://catalog" toViewController:[CatalogController class]];
[map from:@"tt://photoTest1?" toViewController:[PhotoTest1Controller class]];
[map from:@"tt://photoTest2" toViewController:[PhotoTest2Controller class]];
[map from:@"tt://imageTest1" toViewController:[ImageTest1Controller class]];
Using methods from the three20 project, you can set the "url" for, say, a UITableViewCell
to tt://photoTest1
and you'll get a PhotoTest1Controller
's view popped onto the main stack. It's pretty convenient and a great way to start (plus, I found it useful to look through the code and picked up some great patterns from it).
Hope this helps!
Upvotes: 1
Reputation: 18477
Depends on what you're trying to do. The modal view is good for a temporary interruption in the flow of your app. If you're trying to provide a cohesive flow of views that have a deterministic order to them, I would use a UINavigationController
and push
and pop
views in the natural flow. If you have a set of distinctive views that can be selected at any time, a UITabBarController
would be appropriate. Really, it all comes down to the design of your application and how you want the user to interact with your app.
What I would do is sit down and read this article from Apple to figure out what you have at your disposal. Then, I would sit down and design how your app would be best organized.
Go forth and conquer.
Additional information:
Modal View Controllers
Navigation Controllers
Tab Bar Controllers
Upvotes: 4