代码之家  ›  专栏  ›  技术社区  ›  Abha sean808080

在表视图中的单行中显示多个值

  •  0
  • Abha sean808080  · 技术社区  · 12 年前

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

    例如。 数组的计数为10。

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

    但我的问题是,我将表视图单元格设置为:

    第一排:1、2、3、4 第二排:2,3,4,5 第三排:3,4,5,6

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

    索引路径行的单元格:

    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 回复  |  直到 12 年前
        1
  •  2
  •   M.Shuaib Imran    10 年前

    你可以这样做

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