11

我有一个视图控制器,上面有一个按钮。该按钮是隐私政策。单击它时,它会转到正确的 IBAction,然后我创建隐私控制器。

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

我想创建一个隐私控制器的模式视图,该视图具有一个向上动画的 UIWebView 和一个用于在 ios 7 中关闭它的后退按钮。我在网上看到的所有方式都是 ios 6 并且似乎已被弃用。

4

4 回答 4

47

使用这样的东西:

// 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];
于 2013-10-20T07:33:32.830 回答
9

[self presentmodalviewcontroller:vc];已被弃用

你可以试试

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

它会为你工作..

于 2013-10-20T07:33:14.780 回答
6

如果您使用 Storyboard,您也可以使用 segue 来呈现模态视图控制器,并以编程方式进行。

  1. 在您的故事板中,按住 ctrl + 从开始视图下方栏中的文件所有者图标拖动到您要以模态方式呈现的视图,松开并选择“模态”。
  2. 点击 segue 图标,然后在属性检查器中,给它一个标识符,比如“toNewView”。
  3. 在您的起始视图控制器的 .m 文件中,使用此代码执行模态转场:[self performSegueWithIdentifier:@"toNewView" sender:self];

这是一种非常干净的方法,因为您不必导入 .h 文件来实例化该presentViewController方法的第二个控制器对象。

要关闭它,您只需使用unwind segue

于 2014-05-15T03:35:29.527 回答
0
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
taskQueeDetails *privacy = (taskQueeDetails*)[storyboard instantiateViewControllerWithIdentifier:@"taskQueeDetails"];

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

使用代码并更改字符串 instantiateViewControllerWithIdentifier:@"taskQueeDetails"]; 它会正常工作

于 2014-09-06T05:33:48.413 回答