gpt4 book ai didi

ios - 如何使用代码快速移动到现有的 UIViewController(在 Storyboard 中)

转载 作者:行者123 更新时间:2023-11-28 13:12:36 24 4
gpt4 key购买 nike

我知道如何通过单击和拖动来使用按钮来完成此操作,但我有一种情况需要没有按钮的过渡。那么什么代码可以让我从当前的 UIViewController 转换到另一个已经初始化的 UIViewController?

最佳答案

首先,您需要在 Storyboard中创建转场,并为该转场的标识符指定一个合适的名称。您可以通过单击 segue(左面板)然后单击 Attributes(右面板)来执行此操作。

enter image description here

与使用按钮或从 Storyboard中选择表格行来调用此 segue 的方式相同,您可以使用 performSegueWithIdentifier:sender:

从代码中调用它

当在 uitableview 上使用按钮和单元格时,您的 View Controller 调用 prepareForSegue: 如果您需要在 Controller 之间传递任何数据,您可以在 View 中覆盖此方法:

override func prepareForSegue(segue: UIStoryboardSegue?, sender: AnyObject?) {
if segue!.identifier == "MySegue" {
let viewController:ViewController = segue!.destinationViewController as ViewController
viewController.receiveSomedata = self.sendSomeData
}
}

关于ios - 如何使用代码快速移动到现有的 UIViewController(在 Storyboard 中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30794194/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com