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

您可以通过导航访问您的控制器:

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 回答
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];

    }

}

在我的详细信息视图控制器中,我创建了一个 iVar

@interface ProgramacaoDetalhesViewController ()
{
    ProgramacaoModel *_programacao;
}

并设置两种方法,一种接收内容,另一种设置标签

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

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

}
于 2014-05-22T18:06:57.057 回答