2012-08-27 5 views
0

나는 그 안에 3 개의 열과 5 개의 값이있는 2 개의 행을 가진 테이블을 가지고 있습니다. 이 값은 3 열에 연속적으로 표시되어야합니다.값이 3 열로 채우기 테이블 행

indexPath.row 0: Array[0] | Array[1] | Array[2] 
indexPath.row 1: Array[3] | Array[4] | 

내 값을두고 일부 코드를 만들려면 (이 상관하지 않는다 얼마나 예를 들면 5,6,7, ..., 20, 21 행 3 열의 형식) 행은 값이있는 배열의 크기로 계산됩니다.

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{  
    NSMutableArray *values = [... getValues]; 
    int no=0; 
    if (values) { 
     no=(values.count+1)/3; 
    } 
    else{ 
     no=0; 
    } 
    return no; 
} 

현재 문제는 열에 5 개의 값이 분산되어 있습니다. 내가 계산과 주변 struggeling있어 , 이들은 ... 배열의 인덱스

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
//order values in 3 columns and 2 rows (currently)... 
} 

BR, mybecks

답변

0

해결책을 찾았습니다.

NSInteger count = numberOfValues; 
NSInteger start = indexPath.row * 3; 
NSInteger end = MIN(start + 3, count); 

for(int i = start; i < end; i++) 
{ 
    if(i%3 == 0){//left} 
    if(i%3 == 1){//center} 
    if(i%3 == 2){//right} 
} 
0

한다고 가정 COLS을 columss의 숫자가 맞지 않는, 그리고 V는 값의 수, 여기서 M은 행렬이고 Vector는 값 벡터입니다.

for i = 0 to V-1: 
    M[i div COLS][i mod COLS] = Vector[i] 
관련 문제