繁体   English   中英

在ios 7中呈现和消除模态视图

[英]Presenting and dismissing a modal view in ios 7

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

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

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

使用这样的东西:

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

[self presentmodalviewcontroller:vc]; 已被弃用

你可以尝试

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

它会为你工作..

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

  1. 在故事板中,按住Ctrl键并从起始视图下方栏中的文件所有者图标拖动到要模拟显示的视图,然后选择“模态”。
  2. 单击segue图标,然后在Attributes检查器中,为其指定一个标识符,例如“toNewView”。
  3. 在你的起始视图控制器的.m文件中,使用此代码执行模态segue: [self performSegueWithIdentifier:@"toNewView" sender:self];

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

要解雇它,你只需使用展开segue

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”]; 它会工作正常

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM