あるView Controllerから次のView Controllerにいくつかの変数を取得しようとすると、多くの問題が発生します。どうすれば適切に行うことができますか?以下は私のコードです。RedScoreW
これは、変数をBlueScoreW
次のウィンドウに送信できるようにしたいView Controllerです。SWIFT言語を使用してこれを行う方法、特にWATCHOSアプリについて質問しています。
class InterfaceController2: WKInterfaceController {
var RedScoreW = 0
var BlueScoreW = 0
@IBOutlet var WatchRedScoreLabel: WKInterfaceLabel!
@IBOutlet var WatchBlueScoreLabel: WKInterfaceLabel!
@IBAction func RedScorePlus() {
if RedScoreW == 999 {
RedScoreW = 0
WatchRedScoreLabel.setText("0")
}else {
RedScoreW += 1
WatchRedScoreLabel.setText(String(RedScoreW))
}
}
@IBAction func RedScoreMinus() {
if RedScoreW == 0 {
RedScoreW = 999
WatchRedScoreLabel.setText("999")
}
else {
RedScoreW -= 1
WatchRedScoreLabel.setText(String(RedScoreW))
}
}
@IBAction func BlueScorePlus() {
if BlueScoreW == 999 {
BlueScoreW = 0
WatchBlueScoreLabel.setText("0")
} else{
BlueScoreW += 1
WatchBlueScoreLabel.setText(String(BlueScoreW))
}
}
@IBAction func BlueScoreMinus() {
if BlueScoreW == 0 {
BlueScoreW = 999
WatchBlueScoreLabel.setText("999")
}
else {
BlueScoreW -= 1
WatchBlueScoreLabel.setText(String(BlueScoreW))
}
}
override func awakeWithContext(context: AnyObject?) {
super.awakeWithContext(context)
WatchRedScoreLabel.setText(String(RedScoreW))
WatchBlueScoreLabel.setText(String(BlueScoreW))
// Configure interface objects here.
}
override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
}
override func didDeactivate() {
// This method is called when watch view controller is no longer visible
super.didDeactivate()
}
}
これは、RedScoreW 変数と BlueScoreW 変数を使用できるようにしたい Destination View Controller です。
class InterfaceController3: WKInterfaceController {
@IBOutlet var finalRedScoreLabel: WKInterfaceLabel!
@IBOutlet var finalBlueScoreLabel: WKInterfaceLabel!
@IBAction func DoneAndResetButton() {
self.popToRootController()
}
override func awakeWithContext(context: AnyObject?) {
super.awakeWithContext(context)
// Configure interface objects here.
}
override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
}
override func didDeactivate() {
// This method is called when watch view controller is no longer visible
super.didDeactivate()
}
}
* 編集 *
私はこのようにしようとしています、これは私が送信するコードです、確認してください:
@IBAction func FinishButtonPushVariables() {
arrayofScores[0] = RedScoreW
arrayofScores[1] = BlueScoreW
pushControllerWithName("LastScreen", context: arrayofScores)
}
そして、これは私がそれを受け取る場所です...そしてそれは機能しません。笑
@IBOutlet var finalRedScoreLabel: WKInterfaceLabel!
@IBOutlet var finalBlueScoreLabel: WKInterfaceLabel!
@IBAction func DoneAndResetButton() {
self.popToRootController()
}
override func awakeWithContext(context: AnyObject?) {
super.awakeWithContext(context)
let finalarrayofScores = context as? InterfaceController2
finalBlueScoreLabel.setText(String(finalarrayofScores!.arrayofScores[1]))
finalRedScoreLabel.setText(String(finalarrayofScores!.arrayofScores[0]))
// Configure interface objects here.
}