Since I am a newbie in iPhone development, I need some advice on how to structure my xib file in order to get the following (essentially, it should be very similar to Google Places app).
I need a NavigationController with:
- Map with search functionality.
- TableView with search functionality (ideally, the search should be shared between map and TableView).
- One view to show details of a selected item, whatever the source view is (map or table).
- Map view should have a button to show listing view, and viceversa.
My doubt is, what do I have to nest where? I have a NavigationController with its View Controller set to another class with its own xib, but I don’t know how to go on.
Should I create a View with a search bar and another SubView to switch between Map and Table? Or is it better to have two full views each one with its own search bar?
EDIT 1
Finally I have decided to implement the following structure:
- TabBarController
- LugaresNavController (UINavigationController)
- LugaresViewController (UIViewController)
- UISearch
- SubView (UIView)
- MapViewController (UIViewController)
- TableViewController (UITableViewController)
MapViewController and TableViewController have their own xib files. What I want is to have the ability to switch between them into SubView, but I am not able to do it.
I have assigned MapViewController and TableViewController file’s owner to their respective class in the xib files, and also have specified which xib to load at the attributes of their representation in the xib corresponding to LugaresViewController, which is their parent.
When I run the application, all I can see is the TabBar with the NavBar and the UISearch. The frame where SubView should render either the map or the table is showing blank…
What am I doing wrong here?
Your fundamental problem is that you are getting your different parent-child hierarchies confused.
To recap: MVC is Model, View and Controller.
iOS has TWO different parent-child hierarchies: One for the controllers and one for the views.
The following are part of the controller parent-child hierarchy:
This means that LugaresViewController.parentViewController should be LugaresNavController and so on.
However the following doesn’t make any sense:
Views can have subviews but views can’t have subviewcontrollers,
Are you doing the following?
This is a view parent-child hierarchy. This means that:
you can use view transtions to switch between MapViewController.view & TableViewController.view but not viewController transitions (such as presentModal… or push or pop ViewController…).
If this is what you want, then you just have to make sure that you do:
Incidentally, SubView is a terrible name. Usually we call those containerView or something like that.
subview is such an important concept you want to be able to diffrentiate the concept of a subview from the instance of that view. It’s like naming your child “Kid” or your dog “Puppy”.