簡體   English   中英

如何以編程方式更改iOS中的視圖

[英]How to programatically change views in iOS

在Xcode 4.5中,您可以從segue更改視圖,但我想以編程方式更改Mainstoryboard中的視圖。 我知道在Xib。 我們使用這種方法:

SecondViewController *Second = [[SecondViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:Second animated:YES];

我想在用戶在文本字段中單擊完成時更改視圖(此代碼檢測用戶是否單擊完成):

-(IBAction)hidekeyboard {

    [sender resignFirstResponder];
}

您在故事板中創建了一個segue,它來自具有相關文本字段的視圖,並轉到SecondViewController 你必須為它分配一個標識符(也在故事板中,單擊連接兩個視圖控制器的線),讓我們稱之為“segueToSecondViewController”。 然后,您可以使用以下方法手動調用segue:

[self.storyboard performSegueWithIdentifier:@"segueToSecondViewController" sender:self];

segueing的替代方法是從故事板中實例化viewController。

首先,將Storyboard ID分配給storyboard中的viewController。

在此輸入圖像描述

然后,您實例化該viewController,並呈現它。

MBTagEditorViewController *tagEditor = [self.storyboard instantiateViewControllerWithIdentifier:@"TagEditor"];
[self presentModalViewController:tagEditor animated:YES];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM