Is the `UITableViewCellAccessoryCheckmark` image?

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

Thank you very much Carlos

+4
source share
3 answers

This is just a UIView regarding Apple Documentation . So just define it as a UIView.

First you need to create your own subclass of UITableViewCell (in this case it is 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. In addition, you must set the accessView to a UIImageView containing your 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 clicks on a cell, you can simply change the image of the table table accessory.

+6
source

This is one of the standard accessories for UITabelViewCell . Although you can use the image and define your own type of personalized accessory by assigning your custom view (you can add your image here) to the accessoryView property of the UITabelViewCell .

See fpr accessoryType documentation

See the documentation for accessoryView

+2
source

I do not think this is possible with the UITableViewCellAccessoryCheckmark.

  • You will need to create a cell in

     tableView:cellForRowAtIndexPath: 
  • add custom preview or return custom cell

  • Make it look like a check mark or untested based on the state of the data.

0
source

All Articles