I am having issues getting this accomplished correctly. I have a Table View Controller that parses the XML of the podcast loaded with MP3s. On my did select row, I have:
The only warning that I get is that connection is unused, but I am trying to set it up the same way the Apple documentation has it. I then have the following methods implemented:
When I click on the row, the NSLog returns
When I click the row, networkActivityIndicator starts spinning, and goes for a little while and then stops. I also have a Second Table View for the Saved MP3s, where files is a NSMutableArray:
And for the Rows in Table:
However, when I go to that Saved Table View, nothing appears. Am I doing something obviously wrong that the file is not actually downloading?
Code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
RSSEntry *entry = [_allEntries objectAtIndex:indexPath.row];
NSURL *url = [NSURL URLWithString:entry.articleUrl];
NSLog(@"%@", url);
NSURLRequest *theRequest = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60];
receivedData = [[NSMutableData alloc] initWithLength:0];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self startImmediately:YES];
}
Code:
- (void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[receivedData setLength:0];
}
- (void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[receivedData appendData:data];
}
- (void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[connection release];
}
- (NSCachedURLResponse *) connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse {
return nil;
}
- (void) connectionDidFinishLoading:(NSURLConnection *)connection {
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[connection release];
}
Code:
2012-03-12 12:33:42.154 SMCoC[11283:17f03] http://www.smcoc.net/content/audio/sermons/2012/2012_03_11am_the_big_hunt.mp3#!111433318
Code:
- (void)viewWillAppear:(BOOL)animated {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [paths objectAtIndex:0];
NSFileManager *manager = [NSFileManager defaultManager];
self.title = @"Saved Sermons";
self.files = [[manager contentsOfDirectoryAtPath:documentsDirectoryPath error:nil] retain];
self.navigationItem.rightBarButtonItem = self.editButtonItem;
[self.tableView reloadData];
[super viewDidLoad];
[super viewWillAppear:animated];
}
Code:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return [self.files count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = [self.files objectAtIndex:indexPath.row];
UIFont *cellFont = [UIFont fontWithName:@"AmericanTypewriter-Bold" size:17];
cell.textLabel.font = cellFont;
return cell;
}