Reputation: 55534
I have a button that when pressed shows presents a view controller, this is in an Universal app.
On iPhone the view controller is pushed onto the navigation stack. On iPad it is shown in a popover. The new view controller has a delegate which is the view controller responsible for the button, when the user has selected an item the new view controller sends a message to the delegate passing it what the user picked.
I know that whatever presents the popover should be responsible for dismissing it so I keep a reference to the UIPopover, so that I can dismiss it from the view controller responsible for the button (from the same view controller the popover is created).
But I'm unsure who should be responsible for popping the new view controller off the navigation stack, should it be the view controller that allows the user to pick the items, or view controller that has the button?
Should I do:
//Picker view controller
//....
[self.delegate finishedPickingItem:item];
//...
//The first view controller (the self.delegate in the above line):
-(void)finishedPickingItem:(NSString *)item {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[self.profilePopover dismissPopoverAnimated:YES];
} else {
[self.navigationController popToViewController:self animated:YES]; //Or should this be just popViewController:?
}
// do something with item...
}
Or:
//Picker view controller
//...
[self.delegate finishedPickingItem:item];
[self.navigationController popViewControllerAnimated:YES];
//...
//The first view controller (the self.delegate in the above line):
-(void)finishedPickingItem:(NSString *)item {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[self.profilePopover dismissPopoverAnimated:YES];
}
// do something with item...
}
Upvotes: 1
Views: 374
Reputation: 2083
The responsible one is always the one that pushed the view controller on the navigation stack, so your first option. The reason for this is, that you never know how you are displaying your picker view controller, this time you push it on the stack, the next time you present it modal and in that case popping it in the picker won't work.
Upvotes: 1