J'ai eu des problèmes de la modification d'une vue à l'intérieur d'un thread. J'ai essayé d'ajouter une sous-vue, mais il a fallu environ 6 secondes ou plus à l'écran. J'ai finalement obtenu de travail, mais je ne sais pas exactement comment. Donc, je me demandais pourquoi il a travaillé et quelle est la différence entre les méthodes suivantes:
//this worked -added the view instantly
dispatch_async(dispatch_get_main_queue(), ^{
//some UI methods ej
[view addSubview: otherView];
}
//this took around 6 or more seconds to display
[viewController performSelectorOnMainThread:@selector(methodThatAddsSubview:) withObject:otherView
waitUntilDone:NO];
//Also didnt work: NSNotification methods - took also around 6 seconds to display
//the observer was in the viewController I wanted to modify
//paired to a method to add a subview.
[[NSNotificationCenter defaultCenter] postNotificationName:
@"notification-identifier" object:object];
Pour faire référence à cet ont été appelés à l'intérieur de ce Completetion Gestionnaire de la classe de la ACAccountStore.
accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
if(granted) {
//my methods were here
}
}
Edit: Quand je dis qu'il ne marchait pas, je voulais dire qu'il a fallu environ 6 secondes pour afficher la vue, ai-je ajouté.