且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

准备继续查看控制器时出现致命错误

更新时间:2023-02-22 17:21:03

首先像这样更新 ViewController 中的代码:

First Of all Update your code in your ViewController like this:

class ViewController: UIViewController {

@IBAction func action(sender: AnyObject) {

    let alertController: UIAlertController = UIAlertController (title: "Next Page", message: "", preferredStyle: .Alert)

    let yesAction = UIAlertAction (title: "YES", style: .Default ) { action -> Void in self.performSegueWithIdentifier("test", sender: self)
    }

    alertController.addAction (yesAction)

    self.presentViewController(alertController, animated: true, completion: nil)
}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

    if (segue.identifier == "test") {

        let destViewController : SecondViewController = segue.destinationViewController as SecondViewController

        destViewController.textlbl = "Testing Segue"

        }

    }
}

在那之后,我认为你不能用你的方式为 textLabel 赋值,所以在你的 SecondViewController 中以这种方式为该标签赋值:

After that I think you can not assingn value to textLabel with your way so assign value to that label this way in your SecondViewController:

import UIKit

class SecondViewController: UIViewController {

@IBOutlet weak var titleLabel: UILabel!
var textlbl = String()
override func viewDidLoad() {
    super.viewDidLoad()

    self.titleLabel.text = textlbl
    }
}

还有 HERE 我创建了一个示例项目供您参考.

And HERE I cerated a sample project for you for more reference.