Question

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.

Was it helpful?

Solution

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];

OTHER TIPS

[self presentmodalviewcontroller:vc]; has been deprecated.

you can try for

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

it will work for you..

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.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top