gpt4 book ai didi

iphone - 使用 watchConnectivity 发送变量但无法让 watch 应用程序中的选择器更新

转载 作者:行者123 更新时间:2023-11-28 07:56:03 25 4
gpt4 key购买 nike

我一直在尝试从 iPhone 向 watch 发送一个变量。我已设法使用 watchConnectivity 发送它,但我无法让 watch 应用程序中的选择器使用我发送的新变量进行更新。

这是 watch 应用程序的代码:

import WatchKit
import Foundation
import WatchConnectivity

var bigDict = ["":""]

class InterfaceController: WKInterfaceController, WCSessionDelegate {

lazy var keys = Array(bigDict.keys)
lazy var values = Array(bigDict.values)
var pickerItems: [WKPickerItem] = []

@IBOutlet var pickerW: WKInterfacePicker!

@IBAction func pickerDidChange(_ value: Int) {

}

@IBAction func updateButton() {
for item in keys{
let pickerItem = WKPickerItem()
pickerItem.title = item
pickerItem.caption = bigDict[item]
pickerItems += [pickerItem]
}
pickerW.setItems(pickerItems)
}

//func refreshPickerItems() {
//for item in keys{
//let pickerItem = WKPickerItem()
//pickerItem.title = item
//pickerItem.caption = bigDict[item]
//pickerItems += [pickerItem]
// }

//pickerW.setItems(pickerItems)

// }


override func awake(withContext context: Any?) {
super.awake(withContext: context)
// Configure interface objects here.
//refreshPickerItems()
}

override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
if WCSession.isSupported() {
let session = WCSession.default
session.delegate = self
session.activate()
}
}

func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {

}

func session(_ session: WCSession, didReceiveMessage message: [String : Any]) {

print(message)
bigDict = message as! [String : String]
print(bigDict)
}
}

最佳答案

当你收到数据时,你不应该调用“updateButton()”吗?

func session(_ session: WCSession, didReceiveMessage message: [String : Any]) {

print(message)
bigDict = message as! [String : String]
updateButton()
print(bigDict)


}

关于iphone - 使用 watchConnectivity 发送变量但无法让 watch 应用程序中的选择器更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48022145/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com