您好我是编程新手,但我想学习。这是我在swift中的简单代码,每当我打开glance视图然后显示更新的值(如果有的话)时,如何更新illegalAt标签。非常感谢您的帮助
import WatchKit
import Foundation
class GlanceInterfaceController: WKInterfaceController {
@IBOutlet weak var illegalAt: WKInterfaceLabel!
override func awakeWithContext(context: AnyObject?) {
super.awakeWithContext(context)
let sharedDefaults = NSUserDefaults(suiteName: "group.birkyboy.TodayExtensionSharingDefaults")
let illAt = sharedDefaults?.objectForKey("illegalAT") as! String
illegalAt.setHidden(false)
illegalAt.setText(illAt)
// Configure interface objects here.
}
override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
}
}
答案 0 :(得分:2)
每次显示您的Glance时,都会调用willActivate
。这是更新illegalAt
标签的合适位置。