将数据从ios应用程序发送到swift中的watch app中的表视图

时间:2016-09-06 03:40:07

标签: swift uiimage uilabel tableview apple-watch

在我的应用程序中,我正在从ios应用程序发送数据以观看应用程序,该应用程序已成功发送。但我想在表视图中显示相同的数据,该视图显示在watch app的主视图中。即4个标签和1个图像

storyboard image of my watch app

output when running app main View output when running app Table View 表侧主视图的源代码是:

 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)")


        }


    }

0 个答案:

没有答案