2013-06-06 59 views
0

我正在使用iOS 5 & Storyboard.I能夠在「tableView」中顯示來自「http://feeds.reuters.com/reuters/INcricketNews」的RSS源。但是,我無法顯示來自一個特定的單元格,當點擊一個webView.Below是我的代碼。如何在Web視圖中顯示來自表格視圖單元格的RSS條目

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

回答

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]; 
+0

嗯,我試了一下....但它不工作。 – icodes

+0

@sushrut更新了我的答案 –

+0

我欣賞你的答案,但...仍然得到相同的結果... :-) – icodes

相關問題