我想跳转到另一个由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:
更多推荐
发布评论