2009-11-25 2 views
0

UITableViewCellSTyleValue1에 대한 uitableview가 있으므로 textlabel과 세부 텍스트 레이블이 있습니다.NSMutableArray에서 홀수 및 짝수 항목으로 UItableViewCell을 하나 채우는 방법은 무엇입니까?

두 번째로 NSMutableArray가 있습니다. 이제 짝수 항목으로 textLabels을 채우고 홀수 항목으로 detailTextlabels을 채 웁니다.

예를 들어 셀 1은 항목 0을 가져오고 셀 1은 셀 2와 3을 얻습니다.

지금까지 작동하지 않았습니다.

답변

1

해당 셀 레이블간에 배열 항목을 배포하는 데 문제가있는 경우 매우 쉽게 수행 할 수 있어야합니다. 모든 셀이 2 개의 배열 항목을 "소비"하므로 셀 수는 [dataArray 개수]/2와 같습니다. : 당신의 cellForRowAtIndexPath 구현에 그런

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 
     return [dataArray count]/2; 
} 

:

... 
cell.textLabel.text = [dataArray objectAtIndex:2*indexPath.row]; 
cell.detailTextLabel.text = [dataArray objectAtIndex:2*indexPath.row + 1]; 
... 
+0

큰 감사를 많이! – user134282

0
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
// the usual cell creation/reuse stuff.. 

// obtain Label1, 2 by viewWithTag.. 

// index is your instance variable.. 

    index = indexPath.row * 2; 

    Label1.text = [myArr objectAtIndex:index]; 
    Label2.text = [myArr objectAtIndex:index + 1]; 

} 
+0

물론 감사합니다! – user134282

관련 문제