iphone:如何在UITableView中制作多列

ani*_*ani 4 iphone uitableview multiple-columns ios

可能重复:
如何在UITableView中显示多个列?

我有多行和多列数据.但是iPhone UITableView只包含单列和多行.如何按照Apple的人机界面指南显示我的多列数据?有任何想法吗?

Par*_*shi 8

使用GridView满足您的要求,请参阅演示和教程的以下链接...

  1. 网格视图功能于IPhone,使用-的UITableView-1665
  2. GMGridView
  3. UIGridView

我使用下面的代码来显示具有多列的时间表,一些代码用于示例..

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString* cellIdentifier = @"gridCell";
    UITableViewCell *gridCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    if(gridCell == nil)
    {
        gridCell =  [[[UITableViewCellalloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:cellIdentifier] autorelease];
        gridCell.accessoryType = UITableViewCellAccessoryNone;
        gridCell.selectionStyle = UITableViewCellSelectionStyleNone;
    }

    NSArray* items = [_grids objectAtIndex:indexPath.section];

    int imageIndex = 0;
    int yOffset = 0;

    while (imageIndex < items.count)
    {
        int yPos = 4 + yOffset * 74;

        for(int i = 0; i < 4; ++i)
        {
            CGRect  rect = CGRectMake((18 + i * 80), yPos, 40, 40);

            UIImageView* imageView = [self gridImageRect:rect forImage:[items objectAtIndex:imageIndex]];
            [gridCell.contentView addSubview:imageView];
            [imageView release];

            rect = CGRectMake(((80 * i)-4), (yPos+44), 80, 12);

            UILabel* label = [self descriptionOfImage:imageIndex inRect:rect];
            [gridCell.contentView addSubview:label];
            [label release];

            ++imageIndex;

        }

        ++yOffset;
    }

    return gridCell;
}
Run Code Online (Sandbox Code Playgroud)

我希望这有助于你......