Sece to ViewController半自动(似乎工作)(Segue to ViewController semi automatically (seems to work))

编程入门 行业动态 更新时间:2024-10-26 22:17:39
Sece to ViewController半自动(似乎工作)(Segue to ViewController semi automatically (seems to work))

我想跳转到另一个由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) }

接听“主持人播放会话”中的电话......

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

看到称为“控制器”的Segue调用? 我在原始ViewController上放了一个按钮 - 将其链接到收件人并调用标识符“Controller”。

这是一种可接受的方法吗? 我可以删除那里只是创建Segue链接的按钮,因为我知道没有其他方法这样做吗?

I want to jump to another Viewcontroller resulting from the actions of a UIAlertController. I have read that you can't segue programmatically and have found a quick semi-fix which appears too simple and want to get peoples' views.

In the code to setup some MultipeerConnectivity is an UIAlertController, see below.

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) }

Take the call from "Host Play session"...

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

See the call to the Segue called "Controller"? I put a button on the original ViewController - linked it to the recipient and called the Identifier "Controller".

Is this an acceptable approach? Can I remove the button which is there just to create the Segue link because I know no other way of doing this?

最满意答案

正确的方法是从视图控制器创建一个segue到所需的目标视图控制器。 您不需要按钮就可以执行此操作。 您可以通过CTRL +拖动到目标视图控制器从视图控制器创建segue。

更新:

如果您无法从视图控制器场景中CTRL +拖动,请从侧栏中的视图控制器拖动:

在此处输入图像描述

The right way to do this would be creating a segue from your view controller to the desired destination view controller. You do not need a button to do this. You can create a segue from a view controller by CTRL + Dragging to the destination view controller.

Update:

If you can't CTRL + Drag from the view controller scene, drag from the view controller in the sidebar:

enter image description here

更多推荐

本文发布于:2023-04-29 07:51:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1335864.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:工作   ViewController   Sece   Segue   work

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!