简体   繁体   English

xcode 4.2故事板标识符

[英]xcode 4.2 storyboard identifier

I'm writing an app in which I add some buttons to my view (mainView) by code. 我正在编写一个应用程序,其中通过代码在视图(mainView)中添加了一些按钮。 When the user taps on this buttons I want a new view (resultView) to show. 当用户点击此按钮时,我要显示一个新视图(resultView)。

I have both of this views in my storyboard, but since there is no button on my mainView that is in storyboard I can't link the mainView and resultView to each other using storyboard. 我的情节提要板中都有这两个视图,但是由于主视图中的故事板中没有按钮,因此无法使用情节提要板将mainView和resultView彼此链接。 Everything must be done by code. 一切都必须由代码完成。

I want to know how I can link my two views by code and define an identifier for that link. 我想知道如何通过代码链接两个视图并定义该链接的标识符。

Thanks, 谢谢,

To switch the view controller programmatically, you have to set a identifier in the attribute inspector at section "View Controller". 要以编程方式切换视图控制器,必须在属性检查器的“视图控制器”部分中设置标识符。 After that, you can just use the value inside your code. 之后,您可以只使用代码中的值。 Here i used the identifier "Menu". 在这里,我使用了标识符“菜单”。

UIStoryboard *storyboard = self.storyboard;
MenuTableViewController *mtvc = [storyboard instantiateViewControllerWithIdentifier:@"Menu"];

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

There is also a description in the documentation, just look for 在文档中也有描述,只是寻找

Instantiating a Storyboard's View Controller Programmatically 以编程方式实例化情节提要的视图控制器

在IB中的属性检查器中为两者之间的标识符指定一个标识符,然后在按钮上按下事件调用[self performSegueWithIdentifier:@"MySegueIdentifier" sender:theButton]

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

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