-1

I want to create my UITableViewCell like shown in attach image. How can I achieve this thing?
multiple columns

4

4 回答 4

3

创建一个自定义单元格。在 customCell 中进行布局。子类 UITableViewCell。.h 将是

@interface CompanyCell : UITableViewCell
//declare lable imageViews etc
@end

.m 将是

@implementation CompanyCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code for labels imageViews etc
        //add to contentview
        [self.contentView addSubview:imgV>];
    }
    return self;
}

在 viewController.m

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier=@"CellIdentifier";
    CustomCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if(cell==nil)
    {
               cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cell];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
   //access cell.imgV or labels and give data
    return cell;
}
于 2013-07-03T06:24:20.223 回答
1

您应该制作一个自定义UITableViewCellxib,然后将该 xib 用于您的UITableView. 这篇文章应该会有所帮助。

编辑

由于您不想创建 xib,这会有点混乱;但是您仍然可以以编程方式创建UITableViewCell并以编程方式添加subviews到该单元格。然后,在您的单元准备好后,将其设置为cellForRowAtIndexPath方法。

于 2013-07-03T06:28:58.307 回答
0
  1. Create a UICustomCell.
  2. Use the components shown in following image.

enter image description here

And all those lines in background take it as a image. And, add them as a background to your custome cell.

于 2013-07-03T06:35:41.710 回答
0

Yu 可以使用此代码并动态添加您想要的任何内容。我只是向您展示示例代码。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellIdentifier = @"MyCellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                   reuseIdentifier:cellIdentifier]autorelease];
}

UIImage *image_profilepic = nil;
image_profilepic = [UIImage imageNamed:@"blank_image.png"];
cell.imageView.image = image_profilepic;

UIButton *Btnone = [[[ UIButton alloc]init]autorelease];
Btnone.frame = CGRectMake(105, 5.0f, 32.0f, 32.0f);
[cell addSubview:Btnone];

UIButton *btntwo = [[[ UIButton alloc]init]autorelease];
btntwo.frame = CGRectMake(155.0f, 5.0f, 32.0f, 32.0f);
[cell addSubview:btntwo];

UIButton *btnthree = [[[ UIButton alloc]init]autorelease];
btnthree.frame = CGRectMake(205.0f, 5.0f, 32.0f, 32.0f);
[cell addSubview:btnthree];

NSString *name = @"Name";

cell.textLabel.text = name;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
//        CFRelease(aSource);
return cell;
}
于 2013-07-03T06:43:13.483 回答