2012-08-01 2 views
0

원격 서버에서 반환되는 JSON을 구문 분석하는 루프가 있는데이를 통해 루프를 수행하고 값을 가져올 수 있지만 되돌아 오는 데이터로 UITableView를 설정하는 방법을 모르겠습니다.ios - UITableView에서 행 및 값의 수를 설정하여 클릭시 ID로 인식되도록하는 방법은 무엇입니까?

UITableView가 이미 가지고 있다고 생각하는 예상 행 수를 어떻게 재설정합니까? 그리고 실제로 어떻게 값을 설정합니까?

감사합니다.

+0

UITextView 또는 UITableView? – Stunner

+0

@Stunner omg 미안, UITableView ... 인터넷 검색하는 동안 물건을 찾을 수 없습니다 궁금 :) 그냥 내 질문을 변경했다 UITableView – GeekedOut

+1

그런데, 당신은 JSON 구문 분석 루프가 있다고 언급? NSJSONSerialization을 살펴 보시고, 한 줄의 코드로 JSON에서 직접 배열 또는 사전을 반환합니다. – runmad

답변

2

데이터를 배열에 저장하십시오.

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    // when the array is empty, this will just return 0 and your table will 
    // be empty until your data is done downloading 
    return [myArray count]; 
} 

을 그리고 방법으로 데이터 구문 분석 : 그런 다음 데이터를 구문 분석을 완료 한 후과 같이 테이블을 다시로드

-(void)parseFinished { 
    // once the data finished downloading and parsing: 
    [self.tableView reloadData]; 
} 

알고 당신이보기 컨트롤러에 전달해야하는 객체 또는 데이터와 함께해야 할 다른 무엇이든 할 ... 귀하의 질문에, 당신이 원하는의 두 번째 부분에 대한

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    SomeViewController *viewController = [[SomeViewController alloc] initObject:[myArray objectAtIndexPath:indexPath]]; 
    [self.navigationController pushViewController:viewController animated:YES]; 
} 
+0

감사합니다. 혹시 클릭 수를 처리하는 방법을 제게 설명해 주실 수 있습니까? 나는 어떤 ID를 첨부하여 시스템이 어떤 항목을 선택했는지 알 수 있도록 할 수 있습니까? – GeekedOut

+0

내 대답이 업데이트됩니다 ... – runmad

+0

답변이 업데이트되었습니다. – runmad

1

- (void)tableView:(UITableView *) didSelectRowAtIndexPath:(NSIndexPath *)path 
{ 
    NSUInteger column = path.column; 
    NSUInteger row = path.row; 

    //The row and/or column values should be useful in accessing your data source array. 
} 
관련 문제