2011-08-06 1 views
0

다음 형식의 배열이 있습니다.UITableView에 배열을 배열하는 방법?

[NSArray arrayWithObjects: 
[NSArray arrayWithObjects:@"number",@"name",@"date",@"about",nil], 
[NSArray arrayWithObjects:@"number",@"name",@"date",@"about",nil], 
[NSArray arrayWithObjects:@"number",@"name",@"date",@"about",nil], 
[NSArray arrayWithObjects:@"number",@"name",@"date",@"about",nil], 
nil]; 

이 테이블을로드하기 위해이 데이터를 구조화하고 싶습니다.

tableview의 각 행은 배열의 각 행과 일치해야하며 각 셀의 제목은 이름의 하위 배열 objectAtIndex 2와 일치해야합니다.

+0

이 코드는 이미 'UITableView'에 대해 '구조화'되어 있습니다. 'UITableViewCell' 생성을 구현할 코드를 찾고 있습니까? – GarlicFries

+0

잘못된 방식으로 작업하는 것처럼 보입니다 ... 테이블 뷰를 표시하는 방법에 대해보다 구체적으로 설명해야합니다. –

+0

예, 그렇습니다. 셀을 설정하려고합니다. Cell.textlabel.text = [array object at what?]] 배열 내부의 배열이기 때문에. – Jon

답변

2

이 배열은 myData이라는 가정하자 :

는 재사용에 찬성
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    // Return the number of sections. 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    // Return the number of rows in the section. 
    return [myData count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    // Configure the cell... 
    NSArray *obj = [myData objectAtIndex:indexPath.row]; 
    cell.textLabel.text = (NSString*)[obj objectAtIndex:1]; //note: 0=>number; 1=>name,.. 

    return cell; 
} 

, 난 당신이, 예를 들어 얻을 수 있도록 NSDictionaries으로 하위 어레이를 대체하는 제안 이름은 [dict objectForKey:@"name"]입니다.