如果 selectedSegmentIndex 不同,则不同的 ViewController [英] Different ViewController if different selectedSegmentIndex

查看:21
本文介绍了如果 selectedSegmentIndex 不同,则不同的 ViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码是

@IBAction func pressedButton(_ sender: Any) {  
        self.resignFirstResponder()
        if mySegment.selectedSegmentIndex == 0 {

这里我需要,如果我在 ViewControllerA 上选择了 Segment #0(然后按下我的按钮)然后转到 ViewControllerB,如果 Segment #1 那么 ViewControllerC,如果 Segment #2 则 ViewControllerD.
可能吗?

Here I need if I selected Segment #0 on ViewControllerA (and press my button) then go to ViewControllerB, if Segment #1 then ViewControllerC, if Segment #2 then ViewControllerD.
Is it possible?

推荐答案

  1. 首先为每个 viewController 连接一个 segue.control-从 ViewControllerA 顶部的 viewController 图标拖动到另一个 ViewController 并选择 segue 类型.

  1. First wire a segue for each viewController. control-drag from the viewController icon at the top of ViewControllerA to another ViewController and select the segue type.

点击 viewControllers 之间的 segue 箭头,并在右侧的 Attributes Inspector 中设置它的标识符.

Click on the segue arrow between the viewControllers, and set its identifier in the Attributes Inspector on the right.

在按钮代码中,执行以下操作:

In your button code, do the following:

let idx = mySegment.selectedSegmentIndex
let segueID = ["segueToB", "segueToC", "segueToD"][idx]
self.performSegue(withIdentifier: segueID, sender: self)

<小时>

连接两个segue的演示:


Demo of connecting two segues:

这篇关于如果 selectedSegmentIndex 不同,则不同的 ViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆