以编程方式在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
希望它能奏效。