Segue之后TabBar消失(Swift - Xcode)

时间:2018-01-31 04:44:05

标签: ios swift xcode uitabbarcontroller uitabbar

我想知道如何在保持标签栏完整/可见的同时,从正常UIViewController到我的UIViewcontroller(带标签栏)执行segue。请查看附件中的图像以获得更好的参考。

P.S:我尝试了unWindSegue,但它没有解决它,因为我不想在执行segue之前先加载我的第二个UIViewController

PickACardController

import UIKit

class PickCardController: UIViewController {
    @IBOutlet var button1: UIButton!
    @IBOutlet var button2: UIButton!
    @IBOutlet var button3: UIButton!
    var returnValue: Int = UserDefaults.standard.integer(forKey: "tokens")
    var returnValue2: Int = UserDefaults.standard.integer(forKey: "userScore")

    override func viewDidLoad() {
        super.viewDidLoad()
        if (UserDefaults.standard.integer(forKey: "dissapear") == 1)
        {
            button1.setImage(UIImage(named: "wildcardbackingglassesdarken-3x.png"), for: .normal)
            button1.isEnabled = false
        }
        if (UserDefaults.standard.integer(forKey: "dissapear2") == 1)
        {
            button2.setImage(UIImage(named: "wildcardbackingbikini-3x.png"), for: .normal)
            button2.isEnabled = false
        }
        if (UserDefaults.standard.integer(forKey: "dissapear3") == 1)
        {
            button3.setImage(UIImage(named: "wildcardbackingbottomdarken-3x.png"), for: .normal)
            button3.isEnabled = false
        }

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()

    }

    @IBAction func Button1(_ sender: Any) {
        var i: Int = 0
        let randomNumber = arc4random_uniform(3) + 1
        i = Int(randomNumber)

        let alert = AlertController(title: "Congratualations", message: "You earned \(i) tokens!", preferredStyle: .alert)
        alert.setTitleImage(UIImage(named: "token"))
        // Add actions
                alert.addAction(UIAlertAction(title: "Let's See!", style: UIAlertActionStyle.default, handler: { (action) in
                    self.returnValue = self.returnValue + i;
                    UserDefaults.standard.set(self.returnValue, forKey:"tokens")
                    self.performSegue(withIdentifier: "show", sender: nil)
                    }))
            if (returnValue != 30){
                alert.addAction(UIAlertAction(title: "Continue Playing", style: UIAlertActionStyle.default, handler:    { (action) in
                    self.returnValue = self.returnValue + i;
                    UserDefaults.standard.set(self.returnValue, forKey:"tokens")
                    self.performSegue(withIdentifier: "continue", sender: self)
                    }))
            }
        self.present(alert, animated: true, completion: nil)
        UserDefaults.standard.set(1, forKey:"dissapear")
    }

TokenController

import UIKit

class TokenController: UIViewController {
    @IBOutlet var tokens: UILabel?
    @IBOutlet var minus1: UIButton!
    @IBOutlet var minus2: UIButton!
    var returnValue: Int = UserDefaults.standard.integer(forKey: "tokens")
    override func viewDidLoad() {
        super.viewDidLoad()

        tokens?.text = "x\(returnValue)"
    }

enter image description here

1 个答案:

答案 0 :(得分:2)

let storyBoard = UIStoryboard(name: "Main", bundle: nil)
            let vc = storyBoard.instantiateViewController(withIdentifier: "yourTabbarController") as! UITabBarController
self.present (vc, true, nil)

然后

vc.selectedindex = tabof中的indexofyourtokenvc

希望它可以提供帮助