Do NSNotificationCenter notes have higher priority than UITableView cell load events?

Are events dispatched by NSNotificationCenter postNotificationName handled before updating the user interface?

I need to know, because otherwise my current program will crash in some rare cases.

Model Code:

- (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];    
}

When processing notifications, I ran reloadData UITableView.

However, consider whether to update the user interface before processing the notification. In this case, -tableView: cellForRowAtIndexPath: indexPath will be called, but the result object has changed, it will retrieve old data.

+3
source share
3 answers

, postNotification: postNotificationName: object:, , ( ). , , "" .

+5

Apple NSNotificationCenter:

. , postNotification: , .

NSNotificationQueue.

+1

, , . , .

Your data model should know that this is not old data, and should only return the current data to tableViewController. A data model should have full control over data integrity, and it should not be possible to force it to return incorrect data. It definitely should be impossible for the application to crash due to such coercion.

0
source

Source: https://habr.com/ru/post/1727229/


All Articles