2012-04-05 11 views
0

私は、Tabバーアプリケーションでストーリーボード付きのRSSリーダードリルダウンテーブルを開発しようとしています。私はRootTableViewControllerに解析されたXMLを設定することができました。私は今、RootTableViewControllerの各行をポイントし、選択したセルから別のDetailTableViewControllerにデータを渡す方法を試して問題を抱えています。UITableViewはストーリーボードを使用してUITableViewをドリルダウンします

これは、XMLを解析するとRootTableViewController移入するために私のコードの一部です:ストーリーボードで

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return [stories count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *CellIdentifier = @"AdvCurrentCelly"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 
    int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1]; 
    NSString *description = [[stories objectAtIndex: storyIndex] objectForKey: @"description"]; 
    NSString *title = [[stories objectAtIndex: storyIndex] objectForKey: @"title"]; 

    //This populates the prototype cell 'AdvCurrentCelly' 
    cell.textLabel.text = title; 
    //cell.textLabel.text = date; 
    cell.detailTextLabel.text = description 

    return cell; 

} 

を、DetailTableViewControllerにRootTableViewContollerセルからセグエの名前はずっとShowADVDetail

ヘルプですあなたは、任意のタイプのデータを渡すことができますが、私はあなたが表示されます

答えて

1

を高く評価あなたのタイトル文字列を渡す方法。それをmyStringと呼ぶことができます。まず、あなたの文字列を格納するためにあなたのDetailTableViewController.hにプロパティを追加する必要があります:あなたは

@property (strong, nonatomic) NSString *myString

あなたが何をすべきかセグエを伝える必要がありRootTableViewController。このコードを例として使用してください:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    // Refer to the correct segue 
    if ([[segue identifier] isEqualToString:@"ShowADVDetail"]) { 

     // Reference to destination view controller 
     DetailTableViewController *vc = [segue destinationViewController]; 

     // get the selected index 
     NSInteger selectedIndex = [[self.teamTable indexPathForSelectedRow] row]; 

     // Pass the title (from your array) to myString in DetailTableViewController: 
     vc.myString = [NSString stringWithFormat:@"%@", [[stories objectAtIndex:selectedIndex] objectForKey: @"Title"]]; 
    } 
} 
関連する問題