J'ai ce morceau de code:Appel méthode déléguée à partir d'un fil
- (IBAction)registerAction:(id)sender {
[NSThread detachNewThreadSelector:@selector(registerThread) toTarget:self withObject:nil];
}
- (void)registerThread {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
MyDelegate *delegate = (MyDelegate *)[[UIApplication sharedApplication] delegate];
NSInteger locationID = [delegate.api checkCoordinate:[NSString stringWithFormat:@"%f,%f",
location.coordinate.latitude, location.coordinate.longitude]];
NSNumber *status = [api registerWithUsername:usernameField.text
password:passwordField.text email:emailField.text andLocation:locationID];
[self performSelectorOnMainThread:@selector(registrationDoneWithStatus:) withObject:[NSNumber numberWithInt:1] waitUntilDone:NO];
[pool release];
}
cela fonctionne bien, mais parfois je reçois cette erreur:
void _WebThreadLockFromAnyThread(bool), 0x6157e30: Obtaining the web lock from a thread other than the main thread or the web thread. UIKit should not be called from a secondary thread.
Et il semble que seulement en utilisant le délégué Je reçois cette erreur, et je ne sais pas comment résoudre.
Merci d'avance :)
Que voulez-vous dire par: "Vous ne pouvez pas faire une application enfilée en détachant un nouveau thread par rapport à un sélecteur aléatoire."? – patrick
Vous ne pouvez pas prendre de méthode aléatoire et exécuter cette méthode dans un thread via 'detachNewThreadSelector: ...' et avoir l'espoir que la bonne chose se produise. Ne pas dire que c'est ce que vous avez fait ici - juste une règle générale. Le filetage est difficile. – bbum
mhm, comment puis-je définir un point d'arrêt sur _WebThreadLockFromAnyThread? – patrick