2012-08-09 2 views
1

변수를 뷰 컨트롤러에서 다른 컨트롤러로 전달하여 사용자가 첫 번째 테이블 뷰에서 특정 행을 선택하면 응용 프로그램이 그를 선택한 항목의 세부 정보가 표시되는 다른 뷰 컨트롤러로 이동시킵니다. . 이 내 코드입니다 :didSelectRowAtIndexPath를 사용하여 uitableview에서 두 번째 tableview로 변수를 전달하는 방법은 무엇입니까?

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 


    NSString *selectedAuthors = [theauthors objectAtIndex:indexPath.row]; 


    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; 
    Details *dvController = [storyboard instantiateViewControllerWithIdentifier:@"Details"]; //Or whatever identifier you have defined in your storyboard 





    dvController.selectedAuthors = selectedAuthors; 

    UIAlertView *messageAlert = [[UIAlertView alloc] 
           initWithTitle:@"Row Selected" message:authorNAme delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 

    // Display Alert Message 
    authorNAme = [[NSString stringWithFormat:[theauthors objectAtIndex:indexPath.row]] intValue]; 
[messageAlert show]; 

    [self.navigationController pushViewController:dvController animated:YES]; 
} 

selectedAuthors 문자열 AUTHORNAME 내가 선택한 행의 컨텐츠를 저장하고자하는 전역 변수입니다. 도움이 될 것입니다.

+0

에 의해 이미 "데이터"를 두 번째보기 컨트롤러에 전달하고 있습니다. details 뷰 컨트롤러에서 selectedAuthors를 기반으로 세부 정보를 표시해야합니다. – Moxy

+0

특정 문제가 표시 될 링크를 확인하십시오. http://stackoverflow.com/questions/11897149/how-to-send-the-details-of-a-selected-cell-to-another-view-controller –

답변

-1
NSString *titleString = [[[NSString alloc] initWithFormat:@"Element number : %d",indexPath.row] autorelease]; 

이것은 변수를 보내는 데 사용되는 가장 간단한 함수이며 방금 튀지 않았습니다. 잃어버린 사람은 이것이 최고의 기능입니다 !!

1

스토리 보드를 사용하고 있습니다. 이 경우

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 

이 방법은 SEGUE이 실행 되려고 할 때마다 호출되는 구현하기 위해 당신이 다음 뷰 컨트롤러에 정보를 보낼 수 있습니다. 예를 들어, didSelectRowAtIndexPath에서 행 정보를 사전에 저장하고 prepareForSegue 메소드의 다음보기 컨트롤러로 전달할 수 있습니다.

자세한 내용은 SimpleDrillDown이라는 Apple의 샘플 프로젝트를 확인하십시오. `dv.selectedAuthors = selectedAuthors; '에 의해 http://developer.apple.com/library/ios/#samplecode/SimpleDrillDown/Introduction/Intro.html

+0

Xcode에 익숙하지 않아서이 제안을 이미 시도했지만 작동하지 않았습니다 ... plipp을 제공 할 수 있습니다. 많은 감사 –

+0

다음 링크를 확인하십시오 : http://stackoverflow.com/questions/11897149/how-to-send-the-details-of-a-selected-cell-to-another-view-controller –

+0

시도해 보셨나요? 내가 너를 추천 한 프로젝트를 들여다 봐라. 갖고 계시고 작동하지 않는다면 문제가 무엇인지 알 수 있도록 질문을 업데이트하십시오. –

관련 문제