DiscSeven
DiscSeven

Reputation: 3

iPhone Custom TableViewCell problems

I'm trying to create this Custom TableViewCell:

TableViewCell

It's kinda like a UITableViewCellStyleSubtitle only it has two textLabels and two detailTextLabels.

What is the easiest way to accomplish this?

I've tried following apples guide: Apple Table View Programming Guide

But it all ends up not working. If I'm to dig any deeper I'd love to hear what you guys have to say first.

Upvotes: 0

Views: 238

Answers (2)

Akshay
Akshay

Reputation: 5765

I would say the easiest way is to stick with UITableViewCellStyleSubtitle, and set a space separated, formatted string for the detailTextLabel that includes the content of both the subtitles. Something like @"1.20 | 2.10 mil". I say this because both the subtitle strings seems to have the same font style, size, etc. This way, you will not have to implement layoutSubviews.

Upvotes: 0

Christopher A
Christopher A

Reputation: 2961

The quickest and most performant way to implement this would be to add secondary textLabels and detailTextLabels in your init and then position and size them out in layoutSubviews. Init would look like the following.

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{

    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {

        textLabel2 = [[UILabel alloc] init];
        detailTextLabel2 = [[UILabel alloc] init];

        [self.contentView addSubview:textLabel2]; 
        [self.contentView addSubview:detailTextLabel2]; 

    }
    return self;
}

Layout would obviously be custom, but you would just be setting the two new UILabel's frames.

Upvotes: 3

Related Questions