からデリゲートメソッドは、私はこのコードのビットをしました:コールスレッド
- (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];
}
それがうまく動作しますが、時々私はこのエラーを取得する:
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.
そして、唯一のデリゲートを使用しているようですこのエラーが発生し、解決方法がわかりません。事前に
感謝:)
「あなたはランダムセレクタに対して新しいスレッドを切り離してスレッドを作成することはできません。 – patrick
'detachNewThreadSelector:...'を使ってスレッド内でランダムメソッドを実行してそのメソッドを実行することはできません。正しいことが起こることを期待してください。それはあなたがここでやったことではなく、ただの一般的なルールです。スレッディングは難しいです。 – bbum
mhm、どうすれば_WebThreadLockFromAnyThreadにブレークポイントを設定できますか? – patrick