我正在制作一个简单的WatchKit应用程序。我在第一个InterfaceController中有一个golbal int变量,其值为0。
这是我的第一个界面:
import WatchKit
import Foundation
import UIKit
var index:Int = 0
class InterfaceController: WKInterfaceController {
.....
}
在secondView界面中,我想更改此全局变量的值:
import UIKit
import WatchKit
class secondInterfaceController: WKInterfaceController {
override init(context: AnyObject?) {
// Initialize variables here.
super.init(context: context)
// Configure interface objects here.
NSLog("%@ init", self)
println("index: \(index)")
index = 2
}
}
但是我收到一个错误:变量索引“无法分配给该表达式的结果”。我不知道为什么,我想知道如何做到这一点。我可以为IOS的应用程序更改全局变量的值。谢谢
我找到了解决方案。当您想在接口内部使用全局变量时,必须将所有接口设置为相同的“目标成员”
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句