我的NSMutableArray
. 我有这个简洁的代码用于下载文件并显示文件的数据以UITextView
用于测试目的。没有for
循环,一切都很好。给我问题的代码在这个函数中:
- (void)complexDownload {
int i;
for (i=0; i < downloadArray.count; i++) {
if (isBusy == NO) {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
downloadURL = [downloadArray objectAtIndex:i];
NSLog(@"URL is %@", downloadURL);
NSLog(@"Downloading object at index %i", i);
NSURL *url = downloadURL;
NSURLRequest *theRequest=[NSURLRequest requestWithURL:url
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
NSURLConnection *theConnection = [NSURLConnection connectionWithRequest:theRequest delegate:self];
if (theConnection) {
self.downloadData = [NSMutableData data];
isBusy = YES;
NSLog(@"Busy value in download cycle equals %i, downloading", isBusy);
} else {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
NSLog(@"Connection failed");
isBusy = NO;
}
}
}
}
我首先认为问题可能出在 中isBusy
BOOL
,但即使没有if
条件,应用程序也会崩溃。除了这个,编译器没有给我任何错误:
这是大屏幕截图的链接。
其余功能如下:
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[downloadData appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSString *dataString = [[NSString alloc] initWithData:downloadData encoding:NSASCIIStringEncoding];
self.dataTextView.text = dataString;
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
NSLog(@"Download finished!");
isBusy = NO;
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
NSLog(@"%@", error);
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}
所有 NSLogged 值都很好,数组有链接,所有链接都是正确的。