以编程方式在swift中打开viewController [英] Opening viewController programmatically in swift

查看:109
本文介绍了以编程方式在swift中打开viewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过代码在按钮上打开新的UIViewController。我已经在故事板中制作了控制器,只想链接它,我也不想使用XIB接口或nibName?

I want to open new UIViewController on the button through code. I have already made the controller in storyboard and just want to link it and also I don't want to use XIB interface or nibName?

推荐答案

要打开新视图控制器,您需要在按钮单击事件中写入此行:

To open New view controller you need to write this line in button click event:

self.performSegueWithIdentifier("GoToViewController", sender:self)

要连接新的视图控制器,请按照以下步骤操作:

To link up with new view controller follow this steps:


  • 从故事板&中选择新视图控制器右击它

  • Select New view controller from storyboard & right click on it

你会发现Dark dray popup会出现(见图)

You will find Dark dray popup will appear (see image )

现在在Presenting Segues下选择Present Modally&拖动到View控制器,您需要打开此视图控制器&链接

Now under Presenting Segues select Present Modally & drag to the View controller from where you need to open up this view controller & link it

您会在新视图控制器下找到新的segue

You will find new segue created under New view controller

现在选择那个segue去检查员&复制标识符或重命名&复制它

Now select that segue go to inspector & copy the identifier or rename & copy it

在上面的行中使用该标识符

Use that identifier in above line

希望它能奏效。

这篇关于以编程方式在swift中打开viewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆