在WatchKit中更新Glance视图

时间:2015-04-24 20:10:13

标签: swift watchkit

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

1 个答案:

答案 0 :(得分:2)

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