0
我的應用程序應該像這樣工作。問題斯威夫特發送從第一個VC數據的第四個
的問題是,沒有出現在lastVC(空標籤)
到底哪裏出問題了?
import UIKit
class MyChoices {
var colour : String?
var style : String?
var size : String?
}
class VC1: UIViewController {
@IBOutlet weak var nextOutlet: UIButton!
@IBOutlet weak var colourLabel: UILabel!
var choice : MyChoices?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
nextOutlet.hidden = true
}
@IBAction func redButton(sender: AnyObject) {
nextOutlet.hidden = false
colourLabel.text = "Red colour selected"
choice?.colour = "Red"
}
@IBAction func blueButton(sender: AnyObject) {
nextOutlet.hidden = false
colourLabel.text = "Blue colour selected"
choice?.colour = "Blue"
}
@IBAction func greenButton(sender: AnyObject) {
nextOutlet.hidden = false
colourLabel.text = "Green colour selected"
choice?.colour = "Green"
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "lastSegue" {
let nextVC = segue.destinationViewController as! lastVC
nextVC.choice = self.choice
}
}
}
VC2和VC3都非常接近VC1
class lastVC: UIViewController {
@IBOutlet weak var colourLabel: UILabel!
@IBOutlet weak var styleLabel: UILabel!
@IBOutlet weak var sizeLabel: UILabel!
var choice : MyChoices?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
colourLabel.text = choice?.colour
styleLabel.text = choice?.style
sizeLabel.text = choice?.style
}
你應該爲你的數據的數據模型/數據類,然後用它來填補標籤。看看這個:http://stackoverflow.com/questions/32518715/persist-data-and-pass-to-multiple-views – Skywalker
創建一個Model類的sharedInstance,並在你的每個viewController中使用它。 –