UIAlertView Will not show
Posted
by
John
on Stack Overflow
See other posts from Stack Overflow
or by John
Published on 2011-02-21T23:01:55Z
Indexed on
2011/02/21
23:25 UTC
Read the original article
Hit count: 220
I have a program that is requesting a JSON string. I have created a class that contains the connect method below. When the root view is coming up, it does a request to this class and method to load up some data for the root view. When I test the error code (by changing the URL host to 127.0.0.1), I expect the Alert to show. Behavior is that the root view just goes black, and the app aborts with no alert. No errors in debug mode on the console, either. Any thoughts as to this behavior? I've been looking around for hints to this for hours to no avail. Thanks in advance for your help.
Note: the conditional for (error) is called, as well as the UIAlertView code.
- (NSString *)connect:(NSString *)urlString {
NSString *jsonString;
UIApplication *app = [UIApplication sharedApplication];
app.networkActivityIndicatorVisible = YES;
NSError *error = nil;
NSURLResponse *response = nil;
NSURL *url = [[NSURL alloc] initWithString:urlString];
NSURLRequest *req = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10];
NSData *_response = [NSURLConnection sendSynchronousRequest: req returningResponse: &response error: &error];
if (error) {
/* inform the user that the connection failed */
//AlertWithMessage(@"Connection Failed!", message);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Oopsie!"
message:@"Unable to connect! Try later, thanks."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[alert show];
[alert release];
} else {
jsonString = [[[NSString alloc] initWithData:_response encoding:NSUTF8StringEncoding] autorelease];
}
app.networkActivityIndicatorVisible = NO;
[url release];
return jsonString;
}
© Stack Overflow or respective owner