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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With