【问题标题】:How can i make my next view controller change depending on what the title on the button on the first VC is?如何根据第一个 VC 按钮上的标题来更改下一个视图控制器?
【发布时间】:2020-06-05 04:30:19
【问题描述】:

基本上,我的目标是,如果 VC 上的按钮标题是某个东西,则该按钮会将用户带到某个其他 VC,与按钮标题是否是其他东西不同...... 我没有转场,因为我不能去两个地方?

class ThirdViewController: UIViewController {

     @IBOutlet weak var buttonName: UIButton!

    var text:String?

    override func viewDidLoad() {
        super.viewDidLoad()

        self.buttonName.setTitle(self.text, for: .normal)
        // Do any additional setup after loading the view.
    }

    @IBAction func buttonPressed(_ sender: UIButton) {

        func prepare(for segue: UIStoryboardSegue, sender: Any?) {
                  if text == "sad" {
                   _ = segue.destination as! act1ViewController
                  }
                  else if text == "yay" {
                   _ = segue.destination as! act2ViewController
                  }
         }
    }
}

【问题讨论】:

    标签: swift button uiviewcontroller segue


    【解决方案1】:

    您在func 中声明func。这是没有意义的(这里)。你内心的func 不会让任何事情发生;它实际上被忽略了。

    不要在buttonPressed声明任何func。你需要调用一个函数来做你想做的事情。

    如果目标是发生转场,调用函数self.performSegue...。如果情节提要中没有转场,调用函数self.present...self.pushViewController...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-02-09
      • 1970-01-01
      • 2022-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多