iphone: how make Multiple Columns in UITableView [duplicate]

佐手、 提交于 2019-12-01 19:47:06
Paras Joshi

Use GridView for your this requirement, see this bellow links for the Demos and Tutorial ...

  1. Grid-View-in-IPhone-using-UITableView-1665
  2. GMGridView
  3. UIGridView

I use this below code to display Time-Table with multiple columns, Some code for Example ..

- (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;
}

I hope this help you...

Either you can subclass your tableViewCell or you can use this MDSpreadView

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!