开发者

Is `UITableViewCellAccessoryCheckmark` an image?

开发者 https://www.devze.com 2023-03-13 08:37 出处:网络
I need to define a custom UITableViewCell where the UITableVi开发者_JAVA技巧ewCellAccessoryCheckmark is on the left side of a UILabel. Should I define it as an image or is there a smarter way?

I need to define a custom UITableViewCell where the UITableVi开发者_JAVA技巧ewCellAccessoryCheckmark 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号