the situation is like this:
if i don't have internet connection, i show UIAlertView to the user. when the user press "try again", i call "do something".
the problem is the UIAlertView still show for seconds.after the user click "try again"
i tried like:
[self.view setNeedsDisplay];
but,it not works, cause even in the documents,if said the refresh will be only when code control will re开发者_如何学Goturn to the system, and that is not the case here.
thanking in advance.
///////////////////////////////////
if(somecondition)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"NO INTERNET CONNECTION"
delegate:self cancelButtonTitle:nil otherButtonTitles:@"Try Again", nil];
[alert show];
[alert release];
return;
}
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
// the user clicked one of the OK/Cancel buttons
[self DoSomthing];
}
I use this method to detect when the alert is dismissed, I added a line of code to hide it and spawn a new URLrequest, if that's what you need.
-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
alert.hidden=YES;
[webnews loadRequest:[NSURLRequest requestWithURL:home]];
}
The request uses my UIWebView 'webnews' and the NSURL 'home', you will have to adapt these of course.
If you do some lengthy process in the callback from the alert, it will not hide until that callback returns.
So in other words, your doSomething method should not directly try to reconnect to the internet, but just have it spawn off the asynchronous call for doing this.
EDIT: You may delay/detach execution of doSomething with this line of code:
[self performSelector:@selector(doSomething) withObject:nil afterDelay:0];
精彩评论