gpt4 book ai didi

ios - NSNotificationCenter 刷新数据不超过 addObserver

转载 作者:行者123 更新时间:2023-11-28 06:48:47 31 4
gpt4 key购买 nike

我需要使用 NSNotificationCenter 在新数据来自 WCSession 时更新我,以便我可以填写我的 tableview

我在列出的每个函数上都设置了断点,但出于某种原因,它直接转到 NSNotificationCenter.defaultCenter().addObserver(self, selector: "loadList:", name:"load", object: nil)然后没有别的地方

所以有些地方不对劲,你能帮帮我吗?谢谢!

数据管理器:

class DataManager : NSObject, WCSessionDelegate {
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])
evnts.append(Evnt(dataDictionary: ["TeamColor" : tColorValue , "Matchup" : matchValue]))
self.dataObjects = evnts
NSNotificationCenter.defaultCenter().postNotificationName("load", object: nil)

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

}

接口(interface) Controller :

override init() {
super.init()
NSNotificationCenter.defaultCenter().addObserver(self, selector: "loadList:", name:"load", object: nil)
}

func loadList(notification: NSNotification){
//load table data here
doTable()
}

func doTable() {
self.rowTable.setNumberOfRows(DataManager.sharedInstance.dataObjects.count, withRowType: "rows")

for (index, evt) in DataManager.sharedInstance.dataObjects.enumerate() {

if let row = rowTable.rowControllerAtIndex(index) as? TableRowController {
row.mLabel.setText(evt.eventMatch)
} else {
print("nope")
}
}
}

最佳答案

数据管理器:

NotificationCenter.default.post(name: NSNotification.Name(rawValue: "load"), object: nil, userInfo: [String : AnyObject])

接口(interface) Controller :

NotificationCenter.default.addObserver(self, selector: #selector(doThisWhenNotify(notification:)), name: NSNotification.Name(rawValue: "load"), object: nil)
//........


func doThisWhenNotify(notification : NSNotification) {
let info = notification.userInfo
//load your stuff here
}

关于ios - NSNotificationCenter 刷新数据不超过 addObserver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35496441/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com