Bot
Bot

Reputation: 11855

iPhone: View / Edit / List controller

I have a customer view controller that is a subclass of UITableViewController. It has a list that lists all the customers. I have a + button in the top right. I want to make it so when people click the + it will go to the add customer screen and after you click save it will act JUST like the iphone contacts list and then display the newly added customer.

Would I need to create a controller for each view? One to display the list, one to add the person and one to view the contact then another to edit the contact? Or should I use one controller and just add a bunch of views in IB into the single view controller?

Upvotes: 0

Views: 266

Answers (3)

hchouhan02
hchouhan02

Reputation: 946

I suggest you to use different views for every task because using one IB file uses more memory where as if you use different IBs and view controllers for every task then there is not too much memory is used and after completing one task for example when you save the user detail free the memory for that view so that you app do not use much memory.

Upvotes: 0

yuji
yuji

Reputation: 16725

I believe the way the Contacts app does it is:

  • Contacts list is a UITableViewController in a UINavigationController
  • Touching the + modally presents (from the navigation controller) a different view controller for adding the contact
  • Touching Done pushes a new view controller onto the navigation controller for viewing the newly created contact, but it isn't visible yet because the modally presented contact adding view controller is on top. Immediately afterwards, the modal view controller is dismissed, revealing the newly created contact.

To answer your question, I'd suggest using three different view controllers, just like the Contacts app.

Upvotes: 0

twilson
twilson

Reputation: 2062

  1. Create a CustomerListController for seeing ALL customers.
  2. Create a CustomerViewController for viewing and editing the detail.
  3. Subclass the CustomerViewController calling it CustomerAddController for creating, as this will need a little more functionality.

Core Data Recipes application will give you some good pointers around this.

If you want it to only create the record after you hit save, you'll need to:

  1. Create an additional NSManagedObjectContext, assuming you're using Core Data.
  2. Pass that context to the instance of the CustomerAddController class only (not needed for the view class).
  3. When the Save button is hit, you'll need to merge the two NSManagedObjectContext classes in the CustomerListController.

Upvotes: 1

Related Questions