我想更新我的ViewController self.matchedUsers
,這從我經歷了塊異步運行查詢所需數據的屬性。如何從異步檢索的數據更新ViewController的屬性?
然後某處以後當我通過[self.matchedUsers count]
檢索計數時,儘管知道多個對象已添加到我的屬性中,但仍然得到0。我的問題是,即使當我通過塊異步檢索數據時,如何確保我的屬性得到更新?謝謝!
更新:
爲背景,這裏是塊:
//Way earlier in an initializer:
self.matchedUsers = [[NSMutableArray alloc] init];
//In a method much later
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error){
//Code that updates self.matchedUsers with the NSArray objects
dispatch_async(dispatch_get_main_queue(), ^{
[self.matchedUsers addObjectsFromArray: objects];
});
//Question relates to ensure how property could be updated
}
}];
你初始化了匹配用戶嗎? – Jano
您確定您正在檢查__此塊已運行嗎? –
使用KVO或委託或NSNotification或黑色回調來通知您的視圖控制器。 –