在我的应用程序中,当按下某个按钮时,我会调用一个方法 ( postButtonClicked:
),该方法在单独的线程上解析 Web 服务。然后我向用户显示 anUIAlertView
以通知他们呼叫是否成功。
这是我使用的代码:
- (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:
,该应用程序可以正常工作。
我不确定我需要做什么来解决这个问题。