如何对选项卡栏的第二项进行排序? [英] How to make a segue to second item of tab bar?

查看:115
本文介绍了如何对选项卡栏的第二项进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从第二个按钮到选项卡栏的第二个项目进行搜索时,我遇到了一个奇怪的麻烦.我有2个按钮的MainViewController.第一个按钮必须与选项卡栏的第一项链接,第二个按钮必须与选项卡栏的第二项链接.

I have a strange trouble with making of segue to second item of tab bar from second button. I have MainViewController with 2 buttons. First button must be linked with first item of tab bar and second button must be linked with second item of tab bar.

任务看起来很简单.首先进行选择是很基本的(我只是在第一个Tab Bar Controller上链接了第一个按钮),但是在第二个按钮的链接上遇到了麻烦.如果我将第二个按钮与第二个视图链接,我将看到没有选项卡栏的视图控制器.我该怎么办?

The task looks easy. Making segue for first is elementary (I just linked first button first Tab Bar Controller) but I have a trouble with linking of second button. If I link second button with second View I will see view controller without tab bar. What Do I need to do?

推荐答案

您可以使用准备"segue"将其传递到tabView的下一个视图.

You can use prepare for "segue" to pass to the tabView the next view.

1)创建一个CustomTabViewController并加载到您的tabView中.

1) Create a CustomTabViewController and load in your tabView.

2)选择从ViewController到CustomTabBarViewConstroller的动作.

2) select the action from the ViewController to the CustomTabBarViewConstroller.

4)实例化ViewController中的按钮,并使用发件人委托选择要显示的视图.

4) Instantiate the buttons in your ViewController and user the sender delegate to select the view to display.

5)这是您需要的代码.

5) Here is the code that you need.

class ViewController: UIViewController {

// Create a value for chosed view
private var nextViewNumber = Int()

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "tabBar" {

        let nextView = segue.destination as! CustomTabBarViewController

        switch (nextViewNumber) {
        case 1:
            nextView.selectedIndex = 0

        case 2:
            nextView.selectedIndex = 1

        default:
            break
        }
    }
}


@IBAction func FistView(_ sender: UIButton) {
    self.nextViewNumber = 1
    self.performSegue(withIdentifier: "tabBar", sender: self)
}

@IBAction func SecontView(_ sender: UIButton) {
    self.nextViewNumber = 2
    self.performSegue(withIdentifier: "tabBar", sender: self)

}

}

这篇关于如何对选项卡栏的第二项进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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