Reputation: 130
For example I have 3 views:
ListContactView contains dynamic records of Customers. Tap on cell will segue to DetailedContactView.
ListContactView contains 'add' button which segue to SaveContactView.
SaveContactView when user save will go to DetailedContactView.
DetailedContactView, user can 'edit' and goes back to SaveContactView
This is my question:
ListContactView to DetailedContactView OR SaveContactView to DetailedContactView
On viewDidLoad on DetailedcontactView is it possible to call different methods/functions when he comes from a certain view?
I do not want to create some redundant extra duplicated 'alike' view. So is there any best approach?
Upvotes: 0
Views: 255
Reputation: 11995
The correct way is to implement -prepareForSegue:sender:
of SaveContactView and of ListContactView. Cast the destination of the segue to DetailedContactView type and perform custom setup.
// SaveContactView
- (void)prepareForSegue:(UIStoryboardSegue *)segue
sender:(id)sender
{
DetailedContactView *detailedVC = segue.sourceViewController;
[detailedVC setupForShowingFromSaveView];
}
// ListContactView
- (void)prepareForSegue:(UIStoryboardSegue *)segue
sender:(id)sender
{
DetailedContactView *detailedVC = segue.sourceViewController;
[detailedVC setupForShowingFromListView];
}
Upvotes: 0
Reputation: 4909
You can simply apply a check in viewDidLoad
of your DetailedContactView
that who is the parent of this view.
If you are using push segue then check the parent view controller of this view controller in UINavigationControler stack
.
If you are modally present
this DetailedContactView
then find the [self presentingViewController]
and take appropriate action.
Or set a flag from last page to distinguish between parents.
May be this will help you.
Upvotes: 1