gpt4 book ai didi

swift - Segue 到 ViewController 半自动(似乎工作)

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

我想跳转到另一个由 UIAlertController 的操作产生的 Viewcontroller。我读到您无法以编程方式继续搜索,并且找到了一个快速的半修复方法,它看起来太简单了,想要获得人们的意见。

在代码中设置一些 MultipeerConnectivity 是一个 UIAlertController,见下文。

        func showConnectionPrompt() {
let ac = UIAlertController(title: "Connect to Others", message: nil, preferredStyle: .actionSheet)
ac.addAction(UIAlertAction(title: "Host Play session", style: .default, handler: startHosting))
ac.addAction(UIAlertAction(title: "Join Play session", style: .default, handler: joinSession))
ac.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: noSession))
present(ac, animated: true)
}

接听来自“Host Play session”的电话...

    func startHosting(action: UIAlertAction!) {
status = "start"
mcAdvertiserAssistant = MCAdvertiserAssistant(serviceType: "Play", discoveryInfo: nil, session: mcSession)
mcAdvertiserAssistant.start()
performSegue(withIdentifier: "Controller", sender: nil)
}

看到对名为“Controller”的 Segue 的调用了吗?我在原始 ViewController 上放了一个按钮 - 将它链接到接收者并将标识符称为“Controller”。

这是一种可接受的方法吗?我是否可以删除仅用于创建 Segue 链接的按钮,因为我不知道有其他方法可以做到这一点?

最佳答案

正确的方法是创建一个从您的 View Controller 到所需目标 View Controller 的转接。您不需要按钮即可执行此操作。您可以通过 CTRL + 拖动到目标 View Controller 从 View Controller 创建一个 segue。

更新:

如果您不能从 View Controller 场景中按 CTRL + 拖动,请从侧边栏中的 View Controller 拖动:

enter image description here

关于swift - Segue 到 ViewController 半自动(似乎工作),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39773286/

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