【发布时间】:2015-10-17 19:27:01
【问题描述】:
我的 WatchKit 扩展程序中有我需要的所有数据(从 iOS 应用程序传递)。
我用WatchKitInterfaceController中的数据填表,效果很好。
我正在尝试找出在我的 WatchKit ComplicationController 中获取相同数据的最佳方法。
目前,在InterfaceController中,数据使用didReceiveUserInfo传入:
func session(session: WCSession, didReceiveUserInfo userInfo: [String : AnyObject]) {
if let beachValue = userInfo["Surf"] as? String {
places.append(Place(dataDictionary: ["Surf" : surfValue]))
} else {
print("Something went wrong")
}
}
我是否需要在我的ComplicationController 中调用同样的WCSession 方法并再次抓取整个数据,或者是否有任何更简单的方法可以让我访问同样的数据用于ComplicationController?
任何帮助表示赞赏。谢谢!
编辑:
我的表格功能:
func makeTable() {
// Per SO
let myDelegate = WKExtension.sharedExtension().delegate as! ExtensionDelegate
let accessVar = myDelegate.places
self.rowTable.setNumberOfRows(accessVar.count, withRowType: "rows")
for (index, evt) in accessVar.enumerate() {
if let row = rowTable.rowControllerAtIndex(index) as? TableRowController {
row.mLabel.setText(evt.evMat)
} else {
print(“No”)
}
}
}
【问题讨论】:
-
我想知道完全相同 :-) developer.apple.com/library/watchos/documentation/General/… 的 Apple 文档说:// 从扩展委托中获取并发症数据。让 myDelegate = WKExtension.sharedExtension().delegate 为! ExtensionDelegate var 数据:字典 = myDelegate.myComplicationData[ComplicationCurrentEntry]!如果有人可以向 ios 新手解释如何将其应用于我自己的代码,我将不胜感激。基本上我的应用程序数据是一组自定义对象。
-
@Alex 是的,我在文档中也看到了这一点,并试图弄清楚。我不确定它是说使用
ExtensionDelegate作为设置WCSession信息的地方(就像你在iOS 端的AppDelegate中所做的那样)或什么。但是,是的,我也不是很清楚。如果你发现了什么,请告诉我!
标签: ios xcode swift watchkit watchos-2