Craig
Craig

Reputation: 1085

Adding multiple icons in a cell of a UITableViewCell

I have a UITableView with cells in it, and there are buttons to the right of the Table View, so that when I click one of the buttons it takes the selected TableViewCell's label text, and saves it to the array specific to the button that was clicked. The buttons have different colored text, "Green, Blue, Red, Purple, and Orange". What I want to happen, is when I click one of the buttons it will put a colored circle to the right of the text in the cell. The color of the circle will depend on what button was pressed. I feel like you could do something with the accessory view of the cell, but what gets tricky, is when you click another button for that same cell it will put another colored circle in. I want to be able to show 5 circles if needed and if you click the same button again it will take away the circle you previously added. Here is a picture of my app with some photoshoped circles to give you an idea.

enter image description here

Does anyone have any ideas or approaches to this problem. I cant seem to figure out how you would set multiple circles in the accessory view, and how it would effect the text. Would it move the text over?

Help would be much appreciated.

Thanks

Upvotes: 1

Views: 791

Answers (1)

Jerry Thomsan
Jerry Thomsan

Reputation: 1409

you try this code:

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

// In your case it has to be the custom cell object here.

MyCustomCell *cell = (MyCustomCell*)[tableView dequeueReusableCellWithIdentifier:@"AnIdentifierString"];

    if (cell == nil) {
    cell = [[[MyCustomCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"AnIdentifierString"] autorelease];
}

//use your cell here----------

//  cell.textLabel.text = @"This text will appear in the cell";


    return cell;
}

You can override init with style of MyCustomCell as follows for multiple images

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

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

//change frame sizes to palce the image in the cell
    UIImageView * thumbnail1 = [[UIImageView alloc] initWithFrame:CGRectMake(17, 12, 62, 62)];
    thumbnail1.image = [UIImage imageNamed:@"Icon.png"];
    [self addSubview:thumbnail1];

    UIImageView * thumbnail2 = [[UIImageView alloc] initWithFrame:CGRectMake(17, 12, 62, 62)];
    thumbnail1.image = [UIImage imageNamed:@"Icon.png"];
    [self addSubview:thumbnail2];

    UIImageView * thumbnail3 = [[UIImageView alloc] initWithFrame:CGRectMake(17, 12, 62, 62)];
    thumbnail3.image = [UIImage imageNamed:@"Icon.png"];
    [self addSubview:thumbnail3];

}
return self;

}

Upvotes: 1

Related Questions