In my App, when a certain button is pressed, I call a method (postButtonClicked:
) that parses a web service on a separate thread. I then display the user an UIAlertView
to inform them whether the call was successful or not.
Here is the code I use:
- (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 {
...
}
This all worked fine UNTIL I added the alertView:clickedButtonAtIndex:
to the view controller (required for another UIAlertView
I display). Now, every time I call postButtonClicked:
, the App crashes. However, if I remove alertView:clickedButtonAtIndex:
, then call postButtonClicked:
, the App works OK.
I'm not sure what I need to do to fix this.