2014-05-22 2 views
0

웹에서 JSON 콘텐츠를로드하는 TableView가 있습니다. AFNetworking 및 JSONModel을 사용합니다. 그리고이 튜토리얼을 사용하여 데이터 수신 및 구문 분석을 수행합니다. 다음은 코드입니다.다른보기로 JSON 데이터 전달

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

이것은 JSON과 어떤 관련이 있습니까? –

+0

@HotLicks 콘텐츠를 JSON으로 채 웁니다. –

+0

하지만 JSON에서 나온 콘텐츠와 다른 점은 무엇입니까? 귀하의 문제는 JSON과 관련이없는 것처럼 보입니다. –

답변

0

을 내 세부의 ViewController에서 답을

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

    } 

} 

을 찾을 나는 바르

@interface ProgramacaoDetalhesViewController() 
{ 
    ProgramacaoModel *_programacao; 
} 

만들 그리고 두 가지 방법을 설정, 하나는 내용을 받고 다른 하나는 레이블을 설정하는 것입니다.

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

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

} 
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"; 
} 
관련 문제