如何在Web视图中显示表视图单元格中的RSS条目

时间:2013-06-06 08:21:41

标签: iphone uiwebview rss

我正在使用iOS 5& Storyboard。我能够在tableView中显示来自“http://feeds.reuters.com/reuters/INcricketNews”的RSS源。但是当我在webView中点击时,我无法显示来自特定单元格的条目.Below是我的代码。

@interface BlogRss : NSObject          //This is what i am fetching.

@property(nonatomic, copy) NSString * title;
@property(nonatomic, copy) NSString * description;
@property(nonatomic, copy) NSString * linkUrl;
@property(nonatomic, copy) NSString * guidUrl;
@property(nonatomic, retain) NSDate * pubDate;
@property(nonatomic, copy) NSString * mediaUrl;

@end

我的TableViewController配置为 -

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"rssItemCell"];
    if(nil == cell){
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"rssItemCell"];
}
    cell.textLabel.text = [[[[self rssParser]rssItems]objectAtIndex:indexPath.row]title];
    cell.detailTextLabel.text = [[[[self rssParser]rssItems]objectAtIndex:indexPath.row]description];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
  [self performSegueWithIdentifier:@"ShowDetail" sender:self];
}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{
  if ([[segue identifier] isEqualToString:@"ShowDetail"])
{
     ArticleDetailViewController *detailViewController = [segue destinationViewController];
    NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
   // self.entry = [self.allEntries objectAtIndex:indexPath.row];    
   detailViewController.entry = [self.allEntries objectAtIndex:indexPath.row];
     NSLog(@"current row contains  %@ ",detailViewController.entry);  //This shows null.

   }

}

这是我的WebViewController

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    self.newsView.delegate =self;
  //  self.entry =[[BlogRss alloc]init];
    NSURL *url =[NSURL URLWithString:self.entry.linkUrl];
    [self.newsView loadRequest:[NSURLRequest requestWithURL:url]];
    NSLog(@"The URL is %@",url);  //This shows null as well.
}

1 个答案:

答案 0 :(得分:0)

在WebViewController的viewWillAppear中,您正在分配一个新的BlogRss类实例。因此,覆盖prepareForSegue期间分配的条目。

尝试删除以下行:

self.entry =[[BlogRss alloc]init];

您犯的另一个错误是将prepareForSegue中的博客条目分配给self.entry,它指的是表视图控制器,而不是详细视图控制器。

所以在prepareForSegue中更新这一行:

self.entry = [self.allEntries objectAtIndex:indexPath.row];

分为:

detailViewController.entry = [self.allEntries objectAtIndex:indexPath.row];