在FEventTypeChildAdded之前运行的FEventTypeValue

时间:2016-04-26 17:56:32

标签: ios objective-c firebase

我正在查看Firechat demo project,他们使用了一种技术,而他们使用的是FEventTypeChildAdded以及FEventTypeValue,因为后者会在FEventTypeChildAdded之后触发。这样做是为了防止FEventTypeChildAdded回调的“垃圾邮件”以避免UI锁定。但是,我在我的应用中实现了相同的技术,但FEventTypeValue实际上是在FEventTypeChildAdded之前调用的,导致BOOL更改为NO并锁定了用户界面。

来自演示项目:

// This allows us to check if these were messages already stored on the server
// when we booted up (YES) or if they are new messages since we've started the app.
// This is so that we can batch together the initial messages' reloadData for a perf gain.
__block BOOL initialAdds = YES;

[self.firebase observeEventType:FEventTypeChildAdded withBlock:^(FDataSnapshot *snapshot) {
    // Add the chat message to the array.
    if (newMessagesOnTop) {
        [self.chat insertObject:snapshot.value atIndex:0];
    } else {
        [self.chat addObject:snapshot.value];
    }

    // Reload the table view so the new message will show up.
    if (!initialAdds) {
        [self.tableView reloadData];
    }
}];

// Value event fires right after we get the events already stored in the Firebase repo.
// We've gotten the initial messages stored on the server, and we want to run reloadData on the batch.
// Also set initialAdds=NO so that we'll reload after each additional childAdded event.
[self.firebase observeSingleEventOfType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot) {
    // Reload the table view so that the intial messages show up
    [self.tableView reloadData];
    initialAdds = NO;
}];

0 个答案:

没有答案