4

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];
}
Larme
  • 24,190
  • 6
  • 51
  • 81
WebOrCode
  • 6,852
  • 9
  • 43
  • 70
  • try this link http://stackoverflow.com/questions/23102978/swrevealviewcontroller-without-using-navigationcontroller/23105142#23105142 – Anbu.Karthik May 19 '14 at 10:57

3 Answers3

9

Use this to go back

[self dismissViewControllerAnimated:YES completion:nil];
Jojodmo
  • 23,357
  • 13
  • 65
  • 107
ChandreshKanetiya
  • 2,414
  • 5
  • 27
  • 41
0

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.

E-Riddie
  • 14,660
  • 7
  • 52
  • 74
0

In Swift, you can use following line of code to go back to previous view controller without navigation controller:

self.dismissViewControllerAnimated(true, completion: nil)