从ExtensionDelegate阵列没有项目 [英] No items from ExtensionDelegate array

查看:194
本文介绍了从ExtensionDelegate阵列没有项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我号召我的 ExtensionDelegate ComplicationController evnts数组

似乎做工精细调用 ExtensionDelegate InterfaceController ,这两者都是在我的手表应用程序。

但由于某些原因,我得0项 evnts 数组中的调用时,我的 ExtensionDelegate 从我的 ComplicationController

任何想法?谢谢!

ExtensionDelegate

 类ExtensionDelegate:NSObject的,WKExtensionDelegate {    静止无功evnts = [EVNT]()

ComplicationController

  FUNC getCurrentTimelineEntryForComplication(并发症:CLKComplication,withHandler处理程序:((CLKComplicationTimelineEntry) -  GT;无效)){        // extEvnts = 0这里不知何故        让extEvnts = ExtensionDelegate.evnts

这一切工作正常,当我这样做,从我的 InterfaceController 虽然:

  FUNC会话(会话:WCSession,didReceiveUserInfo用户信息:[字符串:AnyObject]){    如果让tColorValue =用户信息[TeamColor]作为?串,让匹配值=用户信息[对决]作为?字符串{        receivedData.append([TeamColor:tColorValue,对决:匹配值])
        ExtensionDelegate.evnts.append(EVNT(数据字典:TeamColor:tColorValue,对决:匹配值))        doTable()    }其他{
        打印(匹配值不一样的字典值)
    }}FUNC doTable(){    让extEvnts = ExtensionDelegate.evnts    self.rowTable.setNumberOfRows(extEvnts.count,withRowType:行)    在extEvnts.enumerate(指数,EVT)(){        如果让行= rowTable.rowControllerAtIndex(指数)作为? TableRowController {            row.mLabel.setText(evt.eventMatch)
        }其他{
            打印(不)
        }
    }
}


解决方案

在声明 evnts ,你就初始化为空数组( [EVNT]())。

当您从访问getCurrentTimelineEntryForComplication(并发症:withHandler:),如果没有修改了阵列,它仍然是空的。

会话(会话:didReceiveUserInfo:),将项目添加到数组,然后立即拨打 doTable(),此时 ExtensionDelegate.evnts 不是空的,因为它包含您添加只是瞬间previously的项目。

被调用,它会出现,这是之前发生会话(假设你没有项目时, getCurrentTimelineEntryForComplication(:withHandler并发症)

会议:didReceiveUserInfo。)发生

如果你想确保你的数据时, getCurrentTimelineEntryForComplication(并发症:withHandler:)被调用时,你应该之前或者在WatchKit这一点上加载一些数据应用程序生命周期。

I'm calling on my ExtensionDelegate from ComplicationController to give an array of evnts.

Seems to work fine calling ExtensionDelegate from InterfaceController, both of which are in my watch app.

But for some reason, I get 0 items in the evnts array when calling on my ExtensionDelegate from my ComplicationController.

Any ideas? Thanks!

ExtensionDelegate:

class ExtensionDelegate: NSObject, WKExtensionDelegate {

    static var evnts = [Evnt]()

ComplicationController:

    func getCurrentTimelineEntryForComplication(complication: CLKComplication, withHandler handler: ((CLKComplicationTimelineEntry?) -> Void)) {

        // extEvnts = 0 somehow here

        let extEvnts = ExtensionDelegate.evnts

This all works fine when I do it from my InterfaceController though:

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

    if let tColorValue = userInfo["TeamColor"] as? String, let matchValue = userInfo["Matchup"] as? String {

        receivedData.append(["TeamColor" : tColorValue , "Matchup" : matchValue])
        ExtensionDelegate.evnts.append(Evnt(dataDictionary: ["TeamColor" : tColorValue , "Matchup" : matchValue]))

        doTable()

    } else {
        print("matchValue are not same as dictionary value")
    }

}

func doTable() {

    let extEvnts = ExtensionDelegate.evnts

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

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

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

            row.mLabel.setText(evt.eventMatch)
        } else {
            print("nope")
        }
    }    
}

解决方案

When you declare evnts, you've initialised it to an empty array ([Evnt]()).

When you access it from getCurrentTimelineEntryForComplication(complication: withHandler:), if nothing has modified the array, it will still be empty.

Inside session(session:didReceiveUserInfo:), you add items to the array, then immediately call doTable(), at which point ExtensionDelegate.evnts is not empty, as it contains the items you added just moments previously.

Given that you have no items when getCurrentTimelineEntryForComplication(complication: withHandler:) is being called, it would appear that this is happening before session(session:didReceiveUserInfo:) occurs.

If you want to make sure that you have data when getCurrentTimelineEntryForComplication(complication: withHandler:) is called, you should load some data before or at that point in the WatchKit application lifecycle.

这篇关于从ExtensionDelegate阵列没有项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆