Domanda

I'm hoping this is an easy one...

I want to replicate what happens in the Contacts app in iOS. The contacts app uses a navigation controller to load a contact's details, great. If you then edit the contact, it will change the buttons in the nav controller as well all the fields on the screen, but it's still operating under the nav controller.

If you create a new contact from the main contact list, you'll get the same edit screen in the form of a modal screen presented over top of your list. This way has a toolbar or something at the top containing your buttons and what not.

How do I replicate this without creating 2 view controller containing the same fields but with one of them having a toolbar?

Any guidance is greatly appreciated, thanks in advance.

È stato utile?

Soluzione

I would probably create an instance variable to denote which mode the controller is in. Perhaps a BOOl property like this:

@property (nonatomic, assign, getter=isEditingMode) BOOL editingMode;

In cases like this I generally create an initializer that takes this as an argument:

- (id)initWithEditingMode:(BOOL)editingMode;

Then all you have to do is use the value of this BOOL to decide what to do with your UI. If you are using a xib file, include your toolbar and then in viewDidLoad hide the toolbar if editingMode is YES.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top