Reputation: 35
I have an initial view controller, say vc1. It has modal buttons, which when selected, takes me to the second view controller, vc2. Inside this view controller (vc2), i have defined a view, say 'view'. Now, After performing some animations, I want to go back to vc1. IS this possible?
I have been able to dismiss the current view using:
[view removeFromSuperview];
But I want to go back to the previous view controller vc1. According to this post: Get to UIViewController from UIView?, I understand that I can get the current UIViewController. But how do I go back to the previous view controller?
Upvotes: 0
Views: 57
Reputation: 3347
I think you're getting Views vs. ViewControllers mixed up. I don't think you need vc2 at all.
Try this in vc1:
Upvotes: 1
Reputation: 153
First, as discussed in the post you referenced, we "should not need to access the view controller directly", I think this will go on the opposite direction of MVC.
And I am not sure how you want to go back to vc1, is this triggered by pressing some button? If you want to go back, you can do this in vc2 rather than the view. You see, in MVC, views just show UI which view controller tell it to do and responds to actions from user, and then view controller handles all the logic, so when you want to go back to vc1, I think it is proper to place the control code in vc2, just bind some action to the view, like a @selector or a block, then the view in vc2 can trigger this, and there you go.
Upvotes: 2
Reputation: 1331
[self dismissViewControllerAnimated:YES completion:nil];
Write this in the animation completion handler or after you remove the view by this your code as you stated,
[view removeFromSuperview];
Upvotes: 0