简体   繁体   中英

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

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.

This is one of the standard accessory type for UITabelViewCell , Although you could use an image and define your own custom accessory view type by assigning your custom view (you could add your image here ) in accessoryView property of UITabelViewCell .

See Documentation fpr accessoryType

See Documentation for accessoryView

I dont think it is possible with UITableViewCellAccessoryCheckmark.

  1. You will have to create a cell in

     tableView:cellForRowAtIndexPath: 
  2. add a custom subview, or return a custom cell

  3. Make it look like a checkmark or unchecked based on the state of the data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM