Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Presenting and dismissing a modal view in ios 7

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.

like image 353
cdub Avatar asked Oct 20 '13 07:10

cdub


People also ask

How do you dismiss a presented view in Swift?

The first option is to tell the view to dismiss itself using its presentation mode environment key. Any view can read its presentation mode using @Environment(\. presentationMode) , and calling wrappedValue. dismiss() on that will cause the view to be dismissed.

How do you dismiss a presented view controller in Objective C?

When it comes time to dismiss a presented view controller, the preferred approach is to let the presenting view controller dismiss it. In other words, whenever possible, the same view controller that presented the view controller should also take responsibility for dismissing it.


2 Answers

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];
like image 61
Jano Avatar answered Oct 05 '22 22:10

Jano


[self presentmodalviewcontroller:vc]; has been deprecated.

you can try for

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

it will work for you..

like image 30
creative_rd Avatar answered Oct 05 '22 22:10

creative_rd