我们怎样才能在三列中拥有TableViewCell

时间:2014-03-03 18:07:10

标签: ios uitableview

我正在尝试在tableview中创建一个图像和标签,其中包含3列中的3个图像。我们如何将tableviewcell分成3列,并在3列中重复相同的图像和标签。

2 个答案:

答案 0 :(得分:1)

您需要创建自定义UITableViewCell才能实现此目的。标准单元格的显示范围非常有限。在线有几个教程(只有谷歌“自定义uitableviewcell”)这是一个:Table View Cells

答案 1 :(得分:0)

@Stonz是对的,您需要使用原型并在cellForRowAtIndexPath中添加一些代码

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    // use a prototype cell
    static NSString *CellIdentifier = @"imageCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    //ImageViews
    UIImageView *image1 = (UIImageView *)[cell viewWithTag:1];
    [image1 setImage:[UIImage imageNamed:@"stack"]];
    UIImageView *image2 = (UIImageView *)[cell viewWithTag:2];
     [image2 setImage:[UIImage imageNamed:@"super"]];
    UIImageView *image3 = (UIImageView *)[cell viewWithTag:3];
     [image3 setImage:[UIImage imageNamed:@"android"]];

    //Label
    UILabel *label1 = (UILabel *)[cell viewWithTag:4];
    label1.text = @"Stackoverflow";
    UILabel *label2 = (UILabel *)[cell viewWithTag:5];
    label2.text = @"Superuser";
    UILabel *label3 = (UILabel *)[cell viewWithTag:6];
    label3.text = @"Android";

    return cell;

}

我为你创建了 DEMO PROJECT

这是一个Screenshot

相关问题