简体   繁体   English

如何以编程方式更改iOS中的视图

[英]How to programatically change views in iOS

In Xcode 4.5 you can change views from a segue, But I want to programatically change views in Mainstoryboard. 在Xcode 4.5中,您可以从segue更改视图,但我想以编程方式更改Mainstoryboard中的视图。 I Know in Xib. 我知道在Xib。 we use this method: 我们使用这种方法:

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

I want to change the view when the user clicks done in the textfield (This code detects if user clicks done): 我想在用户在文本字段中单击完成时更改视图(此代码检测用户是否单击完成):

-(IBAction)hidekeyboard {

    [sender resignFirstResponder];
}

You create a segue in your storyboard that goes from the view that has the text field in question and goes to your SecondViewController . 您在故事板中创建了一个segue,它来自具有相关文本字段的视图,并转到SecondViewController You have to assign an identifier to it (also in the storyboard, click on the line connecting the two view controllers), let's call it "segueToSecondViewController". 你必须为它分配一个标识符(也在故事板中,单击连接两个视图控制器的线),让我们称之为“segueToSecondViewController”。 Then, you can manually call the segue using: 然后,您可以使用以下方法手动调用segue:

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

An alternative to segueing is to instantiate the viewController from the storyboard. segueing的替代方法是从故事板中实例化viewController。

First you assign a Storyboard ID to the viewController in the storyboard. 首先,将Storyboard ID分配给storyboard中的viewController。

在此输入图像描述

Then you instantiate that viewController, and present it. 然后,您实例化该viewController,并呈现它。

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

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

相关问题 以编程方式迭代iOS应用程序中的所有窗口/视图 - Programatically iterate all windows/views in an iOS application 如何以编程方式在视图之间转换? - How to transition between views programatically? 如何在iOS中以编程方式旋转/缩放/更改SCNNode坐标 - How to rotate/scale/change coordinates of SCNNode programatically in ios 如何在Swift iOS(Xcode 6.0)中以编程方式更改UIWebView高度 - How to change the UIWebView height Programatically in Swift iOS (Xcode 6.0) iOS:如何使用XIB以编程方式创建视图,但不使用View Controller - iOS: how to create views programatically using XIB, but without using View Controller iOS Swift UILabel字体大小不会以编程方式更改 - ios swift UILabel font size is not change programatically iOS:以编程方式添加约束作为唯一指标来获取视图高度 - iOS: Getting height of views with programatically added constraints as only indicator 将以编程方式创建的视图垂直添加到滚动视图中(iOS中的线性布局) - Adding programatically created views into scrollview vertically (Linear layout in iOS) iOS | 以编程方式添加两个视图时出现布局约束错误 - iOS | Layout constraint error when adding two views programatically 使用 Swift 以编程方式更改 IOS 的选定选项卡 - Programatically change selected tab for IOS using Swift
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM