NSNotificationCenter通知是否比UITableView单元加载事件具有更高的优先级?

Sim*_*nen 3 iphone objective-c

是否在UI更新事件之前处理了NSNotificationCenter postNotificationName发布的事件?

我需要知道,否则我的当前程序会在极少数情况下崩溃.

型号代码:

- (void)searchFinishedWithResults:(Results *)results {
    self.results = results;
    // If some table cells are loaded NOW, before notication is processed, we might crash!
    [[NSNotificationCenter defaultCenter]
     postNotificationName:SearchResultArrived object:nil];    
}
Run Code Online (Sandbox Code Playgroud)

处理通知时,我将运行UITableView reloadData.

但是,请考虑在处理通知之前,是否必须更新UI.在这种情况下,-tableView:cellForRowAtIndexPath:将调用indexPath,但结果对象已更改,它将获取旧数据.

Adr*_*ski 5

当您以同步方式调用postNotification:或postNotificationName:object:时,将完全调度通知,一个观察者在另一个之后调用(无特定顺序).在您显示的情况下,它们将在您分配变量"results"之后和方法结束之前发送.