0

Web から JSON コンテンツを読み込む TableView があります。AFNetworking と JSONModel を使用しています。そして、このチュートリアルを使用して、データの受信と解析を行います。コードは次のとおりです。

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *identifier = @"CellIdentifier";
        __weak ProgramacaoTableCell *cell = (ProgramacaoTableCell *)[self.tableView dequeueReusableCellWithIdentifier:identifier];

        ProgramacaoModel* programacao = _programacao.programacaoArray[indexPath.row];

        // NameLabel is the Label in the Cell.
        cell.nameLabel.text = [NSString stringWithFormat:@"%@", programacao.atracao ];

        return cell;

    }

このデータを Detail ViewController に渡す方法を知りたいです。私の DetailViewController には、データを受け取るためのプロパティがあります。

@property (nonatomic, strong) IBOutlet UILabel *programacaoNomeLabel;
4

2 に答える 2

0

私は答えを見つける

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Pass the selected object to the new view controller.

    if ([[segue identifier] isEqualToString:@"pushDetalhesView"]) {

        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];

        // Pega o objeto da linha selecionada
        ProgramacaoModel *object = [_programacao.programacaoArray objectAtIndex:indexPath.row];
        // Pass the content from object to destinationViewController
        [[segue destinationViewController] getProgramacao:object];

    }

}

詳細ViewControllerでiVarを作成します

@interface ProgramacaoDetalhesViewController ()
{
    ProgramacaoModel *_programacao;
}

コンテンツを受け取るメソッドと、ラベルを設定するメソッドの 2 つのメソッドを設定します。

- (void) getProgramacao:(id)programacaoObject;
{
    _programacao = programacaoObject;
}

- (void) setLabels
{
    programacaoNomeLabel.text = _programacao.atracao;

}
于 2014-05-22T18:06:57.057 に答える
0

ナビゲーションからコントローラーにアクセスできます。

NSArray* vcStack=[self appDelegate].myNavigationController.viewControllers;
UIViewController* vcUnder;
if(vcStack.count > 0)
    vcUnder=[vcStack objectAtIndex:(vcStack.count-1)];
// -1 depends when you called your controller that's why we test the kind of class
if([vcUnder isKindOfClass:[DetailViewController class]]){
    ((DetailViewController*) vcUnder). programacaoNomeLabel = @"some data";
}
于 2014-05-22T17:08:54.750 に答える