0

Im trying to dismiss a popover from within its content view, and i know that unwind segues is the right way to do this, and it works perfectly well when i create unwind action with storyboard by connecting button to exit icon.

But im stuck with performing same action programatically.

This is my storyboard hierarchy:

[Navigation Controller]
v
[Main View Controller]
v
(popover segue)
v
["B" Tab Bar Controller]
v
[Navigation Controller]
v
["C" View Controller]

So. I have a table view in my "C" View Controller and by tapping on its cell - i want to do some code and then unwind all that stuff all the way to the first Main View Controller.

Easy but not correct way to do this is to send notification to Main View Controller and dismiss popover controller there. Or through delegate or something like that.

But i want to understand how to use "popTo" methods in this situation.

Simple

[self.navigationController popToViewController:[AppModel sharedInstance].mainViewController animated:YES];

just crashes the application with error "Tried to pop to a view controller that doesn't exist."

and im confused about this

mr.dog
  • 315
  • 1
  • 2
  • 11
  • I walk through the process of creating an unwind segue that you invoke programmatically in my answer to this other question: http://stackoverflow.com/a/17607083/1271826 – Rob Aug 17 '13 at 21:28

1 Answers1

0

You created the popover with a seque so if you have a reference of where you want to unwind to then:

- (IBAction)unwindToThisViewController:(UIStoryboardSegue *)unwindSegue
{
}

Sometimes it is better to create popovers programmatically as they are easier to dismiss... Looking at some code I wrote a while back:

 [myPopoverController dismissPopoverAnimated:YES];
David Elliman
  • 1,379
  • 8
  • 15