簡體   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