我已经搜索了一段时间并尝试了很多东西,但我无法让这个错误消失。我有一个通过下拉方法刷新的表。我还使用 Apple 的可达性来确定互联网连接。当我在互联网上运行我的应用程序,然后在应用程序运行时关闭互联网,我的应用程序在尝试显示 UIAlertView 时崩溃。虽然,当我在没有互联网的情况下启动我的应用程序,然后在应用程序运行时打开互联网并将其关闭时,应用程序不会崩溃并且一切正常。任何帮助将不胜感激。
错误发生在 [message show] 行。
编辑代码:
- (void)loadCallList {
NSURL *theURL = [NSURL URLWithString:@"http://www.wccca.com/PITS/"];
NSURLRequest *theRequest = [NSURLRequest requestWithURL:theURL cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:10.0];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection) {
NSLog(@"Reachable");
self.headerHeight = 45.0;
NSData *data = [[NSData alloc] initWithContentsOfURL:theURL];
xpathParser = [[TFHpple alloc] initWithHTMLData:data];
NSArray *elements = [xpathParser searchWithXPathQuery:@"//input[@id='hidXMLID']//@value"];
if (elements.count >= 1) {
TFHppleElement *element = [elements objectAtIndex:0];
TFHppleElement *child = [element.children objectAtIndex:0];
NSString *idValue = [child content];
NSString *idwithxml = [idValue stringByAppendingFormat:@".xml"];
NSString *url = @"http://www.wccca.com/PITS/xml/fire_data_";
NSString *finalurl = [url stringByAppendingString:idwithxml];
xmlParser = [[XMLParser alloc] loadXMLByURL:finalurl];
[callsTableView reloadData];
}
}
else {
NSLog(@"Not Reachable");
self.headerHeight = 0.0;
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"No Internet Connection"
message:@"Please check your internet connection and pull down to refresh."
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[message show];
[message release];
}
[pull finishedLoading];
}