2013-03-25 4 views
0

NSArray을 사용하여 생성 된 레이블로 UITableView을 생성하는 데 사용합니다. 자습서 here을 따랐습니다. 이제 내 서버에서 추출한 동적 콘텐츠로 UITableView을 만들려고합니다.UITableView 동적 셀 내용

그래서
- (void)connectionDidFinishLoading:(NSURLConnection *)connection { 
    NSString *responseString1 = [[NSString alloc] initWithData:responseData1 encoding:NSUTF8StringEncoding]; 

    NSLog(@"%@",responseString1); 

    SBJsonParser *parser = [[SBJsonParser alloc] init]; 
    id sample = [parser objectWithString:responseString1]; 

    tempholder=[NSMutableArray arrayWithCapacity:[sample count]]; 

    for (int i = 0; i < [sample count]; i++) { 
     [tempholder addObject:[[sample objectAtIndex:i]objectAtIndex:0]]; 
     //NSLog(@"%@",[sample objectAtIndex:i]); 
     NSLog(@"%@",[tempholder objectAtIndex:i]); 
    } 
} 

어떻게 내가 'tempholder'내

- (void)viewDidLoad 

에있는

tableData = [NSArray arrayWithObjects:@"Item", @"Item", 
      @"Item", @"Item", @"Item", @"Item", @"Item", 
      @"Item", @"Item", nil]; 

교체하는 : 데이터의 당기 내가 같은 지정이 JSON과 함께 잘 작동 NSMutableArray? 당신이 당신의 JSON을 구문 분석이 끝나면 미리

고맙습니다 ...

+0

다음을 수행

는 tableData은 cellForRowAtIndexPath에서 세포를로드하는 데 사용하는 배열인가? – Petar

답변

1

tempHolder 배열을 tableData로 설정 한 다음 connectionDidFinishLoading : 메서드 끝에 테이블보기를 다시로드하십시오. 코드에서

tableData = tempholder; 
[self.tableView reloadData]; 
1

이 추가 :

self.tableData = [NSArray arrayWithArray:tempholder]; 

그런 다음 당신은 probalby 테이블을 relaod 할 수 있습니다.

1

NSArray를 사용하면 NSMutableArray를 사용할 수 있습니다. tableData 참조를 tempholder로 대체하십시오 (또는 좀 더 의미있는 이름을 tempholder로 바꿉니다). 반대로 정말 필요한 경우 tableData를 tempholder로 설정할 수도 있습니다.

1

대신있는 NSArray의

tableData = [NSArray arrayWithObjects:@"Item", @"Item", @"Item", @"Item", @"Item", @"Item", @"Item", @"Item", @"Item", nil]; 

그것을 위해있는 NSMutableArray를 사용 viewDidLoad에 운전 방식에있는 NSArray를 초기화 할 수 있습니다. 당신은 서버에서 데이터를받을 때 다음, 단지

[tableData removeAllObjects]; 
tableData = tempholder 
+0

NSArray를 편집 할 수 없으므로 NSArray를 편집 할 수 없기 때문에 NSMutableArray에서 나중에 편집 할 수 있습니다. –

+0

[tableData removeAllObjects]를 사용할 수 없습니다 ... SIGBART 오류가 발생했습니다 ... –

+0

그 유형이 NSMutableArray이어야하며 removeAllObjects를 삭제할 수 있습니다. –