Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is `UITableViewCellAccessoryCheckmark` an image?

I need to define a custom UITableViewCell where the UITableViewCellAccessoryCheckmark is on the left side of a UILabel. Should I define it as an image or is there a smarter way?

Many thanks, Carlos

like image 857
carvil Avatar asked Feb 23 '23 21:02

carvil


1 Answers

It's just an UIView regarding to the Apple Documentation. So just define it as an UIView.

First you have to create your own subclass of UITableViewCell (in this case it's called MyCell). In this class, define the frame of your AccessoryView in the layoutSubviews method.

- (void)layoutSubviews {
    [super layoutSubviews];
    self.accessoryView.frame = CGRectMake(0, 0, 20, 20);
}

In your view controller, tell the table to use this class as a cell. Additionaly you have to set the accessoryView to the UIImageView containing you image.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[MyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        cell.accessoryView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"check.png"]] autorelease];
    }
    // Configure the cell.
    return cell;
}

When the user taps on a cell you can simply change the image of the accessoryView of the table cell.

like image 199
audience Avatar answered Feb 26 '23 09:02

audience