私のアプリでは、特定のボタンが押されたときpostButtonClicked:
に、別のスレッドでWebサービスを解析するメソッド()を呼び出します。次に、ユーザーにanを表示してUIAlertView
、呼び出しが成功したかどうかを通知します。
私が使用するコードは次のとおりです。
- (void)postButtonClicked:(id)sender {
[NSThread detachNewThreadSelector:@selector(postViaWebservices) toTarget:self withObject:nil];
}
- (void)postViaWebservices {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
WebServiceManager *wsm = [[WebServiceManager alloc] init];
BOOL success = [wsm callPost];
if (success) {
[self performSelectorOnMainThread:@selector(postSuccess) withObject:nil waitUntilDone:NO];
} else {
[self performSelectorOnMainThread:@selector(postFailure) withObject:nil waitUntilDone:NO];
}
[wsm release];
[pool release];
}
- (void)postSuccess {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:nil
message:@"Success message"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
- (void)postFailure {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:nil
message:@"Failure message"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
...
}
alertView:clickedButtonAtIndex:
ビューコントローラにを追加するまで、これはすべて正常に機能しました(別のUIAlertView
表示に必要です)。これで、電話をかけるたびにpostButtonClicked:
アプリがクラッシュします。ただし、削除alertView:clickedButtonAtIndex:
してから呼び出すpostButtonClicked:
と、アプリは正常に動作します。
これを修正するために何をする必要があるのかわかりません。