0

My table keeps ending up empty because didRecieveUserInfo isn't called until after doTable() gets called.

I'm getting all the correct data in didRecieveUserInfo, but my app doesn't know that because didRecieveUserInfo isn't getting called until after the table is already set up.

Any ideas? I feel like it must be something simple, here is my code:

ExtensionDelegate:

func applicationDidFinishLaunching() {
    if (WCSession.isSupported()) {
        let session = WCSession.defaultSession()
        session.delegate = self
        session.activateSession()
    }
}

func session(session: WCSession, didReceiveUserInfo userInfo: [String : AnyObject]) {


    if let tCValue = userInfo["Tr"] as? String, let mValue = userInfo["Mp"] as? String {

        receivedData.append(["Tr" : tCValue , "Mp" : mValue])
        evn.append(Evnt(dataDictionary: ["Tr" : tCValue , "Mp" : mValue]))

    } else {
        // None
    }

}

InterfaceController:

override func willActivate() {
    // This method is called when watch view controller is about to be visible to user
    super.willActivate()
    doTable()
}

func doTable() {

    if WCSession.defaultSession().reachable == true {

    // SO
    let myDelegate = WKExtension.sharedExtension().delegate as! ExtensionDelegate
    let evM = myDelegate.evn

    self.rowTable.setNumberOfRows(evM.count, withRowType: "rows")


    for (index, evt) in evM.enumerate() {

        if let row = rowTable.rowControllerAtIndex(index) as? TableRowController {

            row.mLabel.setText(evt.maT)

        } else {
          // None  
        }
    }

    }
    else {
          // None  
    }
}
SRMR
  • 3,064
  • 6
  • 31
  • 59

1 Answers1

1

Implement the WCSession Delegate in the Interfacecontroller and call the doTable() after you receive your data

Jonas
  • 2,139
  • 17
  • 38
  • That's what I was doing before, but I was trying to move a lot of the logic out of the `InterfaceController` into the `ExtensionDelegate` so that it could be accessed by the `ComplicationController`, or will it not matter if the WCSessionDelegate is in the `InterfaceController` when it concerns the Complication Controller? Thanks! – SRMR Feb 15 '16 at 21:58
  • I think it must be in the InterfaceController. You can check this detailed answer on so:http://stackoverflow.com/questions/32214868/get-data-to-complication-extensiondelegate-not-called – Jonas Feb 15 '16 at 22:01