在我的应用程序中,我正在从ios应用程序发送数据以观看应用程序,该应用程序已成功发送。但我想在表视图中显示相同的数据,该视图显示在watch app的主视图中。即4个标签和1个图像
class InterfaceController: WKInterfaceController, WCSessionDelegate {
var session: WCSession!
var MessageData = NSMutableDictionary()
@IBOutlet var watch_displayImage: WKInterfaceImage!
@IBOutlet var watch_ticket_category: WKInterfaceLabel!
@IBOutlet var watch_ticketType: WKInterfaceLabel!
@IBOutlet var watch_ticketTime: WKInterfaceLabel!
@IBOutlet var watch_ticketDate: WKInterfaceLabel!
override func awakeWithContext(context: AnyObject?) {
super.awakeWithContext(context)
if WCSession.isSupported()
{
session = WCSession.defaultSession()
session.delegate = self
session.activateSession()
}
}
override func willActivate()
{
super.willActivate()
}
func session(session: WCSession, didReceiveMessage message: [String : AnyObject], replyHandler: ([String : AnyObject]) -> Void)
{
MessageData = NSMutableDictionary(object: message, forKey: "data")
print("\(MessageData)")
let imgdata = MessageData["data"]!["Watchdat"]!!["image_data"] as! NSData
watch_ticket_category.setText("\(MessageData["data"]!["Watchdat"]!!["ticket_category"] as! String)")
watch_displayImage.setImageData(imgdata)
watch_ticketType.setText("\(MessageData["data"]!["Watchdat"]!!["ticket_type"] as! String)")
watch_ticketTime.setText("\(MessageData["data"]!["Watchdat"]!!["time"] as! String)")
watch_ticketDate.setText("\(MessageData["data"]!["Watchdat"]!!["date"] as! String)")
}
Source code for watch app(tableView) tried so far is:
var dic = NSMutableDictionary()
let array_data = NSMutableArray()
var session: WCSession!
override func awakeWithContext(context: AnyObject?)
{
super.awakeWithContext(context)
if WCSession.isSupported()
{
session = WCSession.defaultSession()
session.delegate = self
session.activateSession()
}
loadTableData()
}
func loadTableData()
{
historyTable.setNumberOfRows(array_data.count, withRowType: "cell")
for i in 0..<array_data.count
{
if let cell = historyTable.rowControllerAtIndex(i) as? HistoryCell
{
let dic = array_data[i] as! NSMutableDictionary
let imgdata = dic["data"]!["Watchdat"]!!["image_data"] as! NSData
cell.image.setImageData(imgdata)
cell.category.setText("\(dic["data"]!["Watchdat"]!!["ticket_category"] as! String)")
cell.type.setText("\(dic["data"]!["Watchdat"]!!["ticket_type"] as! String)")
cell.date.setText("\(dic["data"]!["Watchdat"]!!["date"] as! String)")
cell.time.setText("\(dic["data"]!["Watchdat"]!!["time"] as! String)")
}
}