11

I have a view controller that has a button on it. The button is the Privacy Policy. When it's clicked it goes to the proper IBAction and I create the privacy controller.

 - IBAction ...
{
    PrivacyPolicyViewController *privacy = [[PrivacyPolicyViewController alloc] init];
    .....
}

I want to create a modal view of the privacy controller that has a UIWebView that animates itself upward and a back button to close it in ios 7. The ways I see online all are ios 6 and seem deprecated.

cdub
  • 24,555
  • 57
  • 174
  • 303

4 Answers4

47

Use something like this:

// assuming your controller has identifier "privacy" in the Storyboard
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
PrivacyPolicyViewController *privacy = (PrivacyPolicyViewController*)[storyboard instantiateViewControllerWithIdentifier:@"privacy"];

// present
[self presentViewController:privacy animated:YES completion:nil];

// dismiss
[self dismissViewControllerAnimated:YES completion:nil];
Jano
  • 62,815
  • 21
  • 164
  • 192
9

[self presentmodalviewcontroller:vc]; has been deprecated.

you can try for

[self presentViewController:viewController animated:YES completion:nil];

it will work for you..

Rashad
  • 11,057
  • 4
  • 45
  • 73
creative_rd
  • 695
  • 6
  • 13
6

If you are using Storyboards, you can use a segue to present a modal view controller as well, and do it programmatically.

  1. In your storyboard, ctrl+drag from the File's owner icon in the bar under the starting view to the view you want to present modally, let go and select "modal".
  2. click on the segue icon, and then in the Attributes inspector, give it an identifier, like "toNewView".
  3. in your starting view controller's .m file, use this code to perform the modal segue: [self performSegueWithIdentifier:@"toNewView" sender:self];

It's a nice clean way to do it because you don't have to import a .h file to instantiate the second controller object for the presentViewController method.

To dismiss it, you just use an unwind segue.

Community
  • 1
  • 1
inorganik
  • 24,255
  • 17
  • 90
  • 114
  • Thanks for this! Is there any way to access the sender from the ViewController segued-to? – Ruben Martinez Jr. Jul 16 '14 at 22:08
  • 1
    @RubenMartinezJr. You would actually determine where you are segueing before you segue. Use the `prepareForSegue` method, and inside that use `if ([segue identifier] isEqualToString:@"someView"])` for conditional actions depending on where you are segueing. – inorganik Jul 16 '14 at 23:03
0
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
taskQueeDetails *privacy = (taskQueeDetails*)[storyboard instantiateViewControllerWithIdentifier:@"taskQueeDetails"];

// Present the modal
[self presentViewController:privacy animated:YES completion:nil];

use the code and change the string instantiateViewControllerWithIdentifier:@"taskQueeDetails"]; it will work fine

Glen Selle
  • 3,966
  • 4
  • 37
  • 59
NRV
  • 21
  • 1