0

タブバーアプリでストーリーボードを使用したRSSリーダードリルダウンテーブルを開発しようとしています。RootTableViewControllerに解析済みのXMLを入力することができました。RootTableViewControllerの各行がポイントし、選択したセルから別のDetailTableViewControllerにデータを渡す方法を理解するのに問題があります。

これは、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;

}

ストーリーボードでは、RootTableViewContollerセルからDetailTableViewControllerへのセグエの名前は次のとおりです。ShowADVDetail

感謝します

1月

4

1 に答える 1

1

任意のタイプのデータを渡すことができますが、Title 文字列を渡す方法を紹介します。それを 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"]];
    }
}
于 2012-04-12T00:58:33.767 に答える