你好,我是编程新手,但我想学习。这是我在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()
    }
}

最佳答案

每次显示您的浏览时,都会调用willActivate。这是更新illegalAt标签的适当位置。

10-05 20:05