0

I'm trying to pop the current view controller from navigation controller. I want to do this from a subview that's buried pretty far down the view hierarchy. In my UIView subclass, I have a method:

- (void)back
{
    NSLog(@"View should pop now...");
    [[UIApplication sharedApplication] sendAction:@selector(popViewControllerAnimated) 
                                               to:nil 
                                             from:self 
                                         forEvent:nil];
}

But this doesn't work, nor does it throw any sort of error. What is going on here? Why does the action not progress up the responder chain like it's supposed to according to the documentation?

Alex
  • 21,273
  • 10
  • 61
  • 73
zakdances
  • 22,285
  • 32
  • 102
  • 173

2 Answers2

1

I recommend you use the notification center for this. Then the view hierarchy doesn't matter.

Or you could add the view controller as a target to the button.

dasdom
  • 13,975
  • 2
  • 47
  • 58
0

Forgot to add the colon:

@selector(popViewControllerAnimated:)

Still, the behavior is very glitchy. Sometimes the transition is animated, sometimes it isn't and I'm not able to send popViewControllerAnimated's BOOL argument.

zakdances
  • 22,285
  • 32
  • 102
  • 173