Reputation: 7294
How can to go back to previous view programmatically without UINavigationController
, because all examples that I have found use UINavigationController
?
I am making view for sending feedback and I would like to use this view in many more apps.
If I use UINavigationController than app need to have UINavigationController
to use my view for sending feedback.
Is this possible to do and how ?
This is code how I show my view for sending feedback:
- (IBAction)showFeedbackView:(id)sender {
WOC_FeedbackViewController *feedbackView = [[WOC_FeedbackViewController alloc] init];
[self presentViewController:feedbackView animated:YES completion:nil];
}
Upvotes: 4
Views: 2890
Reputation: 2414
Use this to go back
[self dismissViewControllerAnimated:YES completion:nil];
Upvotes: 9
Reputation:
In Swift, you can use following line of code to go back to previous view controller without navigation controller:
self.dismissViewControllerAnimated(true, completion: nil)
Upvotes: 0
Reputation: 14780
Depending on what your project works (Storyboards or XIB) you can use presentViewController. But thats when you keep a reference on your last viewController's identifier.
If you know the ID of your viewController NSString *yourID;
1) Init your viewController
For storyboard
UIViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:yourID];
For XIB
UIViewController *vc = [UIViewController alloc]initWithNibName:yourID bundle:nil];
2) Presenting your ViewController
[self presentViewController:vc animated:YES completion:nil];
P.S This is a way to do this, but you should use navigationController
because you can keep memory of a viewController
on stack so when you need to access it again, you can access it faster. In other words, UINavigationController
is applied in every iOS Application you see on App Store.
Upvotes: 0