0

I have a TableView that load JSON content from web. I use AFNetworking and JSONModel. And I use this tutorial do Receive and Parse the Data Here is the code.

    - (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;

    }

I want to know how pass this data to a Detail ViewController. In my DetailViewController i have the properties to receive the data.

@property (nonatomic, strong) IBOutlet UILabel *programacaoNomeLabel;
  • What does this have to do with JSON? – Hot Licks May 22 '14 at 18:15
  • @HotLicks I fill the content with JSON. – Diego Rodrigues May 22 '14 at 19:10
  • But, given the content, how does it differ, having come from JSON, vs having come from some other source? Your problem doesn't appear to have anything to do with JSON. – Hot Licks May 22 '14 at 19:19
  • Yes, I only mention this @HotLicks because maybe someone find important mention that. – Diego Rodrigues May 22 '14 at 22:08
  • But already find the answer thanks – Diego Rodrigues May 22 '14 at 22:08
  • Very often "JSON" is viewed as a dreadful monster hanging over the program, and it's somehow felt that "JSON data", once deserialized into program objects, is somehow "special", and ordinary programming and debugging techniques do not apply. This leads to unnecessary angst and often prevents the programmer from actually understanding what's going on. – Hot Licks May 22 '14 at 22:33

2 Answers2

0

You can access to your controller through your navigation:

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";
}
brcebn
  • 1,571
  • 1
  • 23
  • 46
0

I find the answer

- (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];

    }

}

In my Details ViewController I create an iVar

@interface ProgramacaoDetalhesViewController ()
{
    ProgramacaoModel *_programacao;
}

And set two method, one to receive the content and another to set the Labels

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

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

}