在tableview中显示单行中的多个值

时间:2013-03-28 13:45:14

标签: iphone uitableview ios6

我在数组中有动态值。我必须在一行中显示4个值,在另一行中显示剩余值。

例如。 数组的数量是10。

第1行包含1,2,3,4 第2行包含5,6,7,8
第3行包含9,10。

但我的问题是,我得到了tableview单元格:

第一排:1,2,3,4 第2排:2,3,4,5 第3排:3,4,5,6

我正在尝试很多事情,但没有得到确切的灵魂。

indexpath的行的单元格:

if (rowcount % 4)
 {
     for (k=0; k<4; k++)
     {
       btnexpand = [[UIButton alloc] init];
       btnexpand = [UIButton buttonWithType:UIButtonTypeCustom];
       btnexpand.frame = CGRectMake(j, 5, 80, 40);
       [btnexpand setTitle:[NSString stringWithFormat:@"Step %d",[[[[appDelegate.array_proj objectAtIndex:indexPath.section] arr_task] objectAtIndex:indexPath.row - 1+k] taskid]] forState:UIControlStateNormal];


       [cell.contentView addSubview:btnexpand];

        j = j + 65;
       }
    }
    else
    {
       for (k=0; k<rowcount%4; k++)
        {
           btnexpand = [[UIButton alloc] init];
           btnexpand = [UIButton buttonWithType:UIButtonTypeCustom];
           btnexpand.frame = CGRectMake(j, 5, 80, 40);

            [btnexpand setTitle:[NSString stringWithFormat:@"Step %d",[[[[appDelegate.array_proj objectAtIndex:indexPath.section] arr_task] objectAtIndex:indexPath.row - 1+k] taskid]] forState:UIControlStateNormal];


             [cell.contentView addSubview:btnexpand];

              j = j + 65;
       }

}

1 个答案:

答案 0 :(得分:2)

你可以这样做

int initialIndex = indexPath.row * 4;
for (int i=initialIndex ; i<initialIndex+4 && i< totalValues ; i++)
{
    //USE i for getting IndexValue


}