0

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

@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.
}
4

1 回答 1

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];
于 2013-06-06T10:20:21.380 回答