- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
[self getLoadingTableCellWithTableView:tableView];
RssItemCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RssItemCell"];
// If break in here, url fetch maybe error or row is null
RssItem *feed = [[self.manager.feeds objectForKey:self.manager.currentChannel] objectAtIndex:indexPath.row];
cell.title.text = feed.title;
cell.description.text = feed.description;
cell.date.text = feed.date;
// if any image enclosure at rss parse
[cell.enclosure setImage:[UIImage imageNamed:@"logo.png"]];
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue,
^{
UIImage *image = [[UIImage alloc] initWithData:feed.enclosure];
[cell.enclosure setImage:image];
[cell setNeedsLayout];
});
return cell;
}
当我尝试获取 RSS 的空行时遇到问题(我的网络类别上没有帖子)
我想显示警报并自动转到主页。
卡在这里。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
[self getLoadingTableCellWithTableView:tableView];
RssItemCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RssItemCell"];
@try {
NSLog(@"Trying to tetch");
// If break in here, url fetch maybe error or empty row
RssItem *feed = [[self.manager.feeds objectForKey:self.manager.currentChannel] objectAtIndex:indexPath.row];
cell.title.text = feed.title;
cell.description.text = feed.description;
[cell.enclosure setImage:[UIImage imageNamed:@"logo.png"]];
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue,
^{
UIImage *image = [[UIImage alloc] initWithData:feed.enclosure];
[cell.enclosure setImage:image];
[cell setNeedsLayout];
});
return cell;
}
@catch (NSException *e) {
NSLog(@"catching %@ reason %@", [e name], [e reason]);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:[NSString stringWithFormat:@"%@",e] delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
TableViewController *VC = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewController"];
[self presentViewController:VC animated:YES completion:nil];
}
@finally {
NSLog(@"finally");
}
}
警报不出现并转到断点。我应该如何处理这个错误?