VarunMurali
VarunMurali

Reputation: 413

Special Custom Checkmark in UITableViewCell

As I understand it, the UITableViewCellAccessoryTypeCheckmark appears when the row is tapped/untapped.

However, I would like to make an accessory that is always visible. Like a Checkbox or something of the sort. This is because i want to display additional information if the row is selected but if the Checkbox at the right end of the row is tapped, a tick should appear in it.

Sorry if I was not very clear. Please ask me for any clarifications.

Thanks!

Upvotes: 0

Views: 943

Answers (4)

Albert Zhang
Albert Zhang

Reputation: 777

You have to create your custom accessory view. In that view you add two UIImageView, and give a tag for the checkbox.

On create:

#define CHECKBOX_TAG 123

UIView *customAccessoryView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 60, 30)] autorelease];
UIImageView *otherInfo = [[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)] autorelease];
UIImageView *checkbox = [[[UIImageView alloc] initWithFrame:CGRectMake(30, 0, 30, 30)] autorelease];
checkbox.tag = CHECKBOX_TAG;
[customAccessoryView addSubview:otherInfo];
[customAccessoryView addSubview:checkbox];
cell.accessoryView = customAccessoryView;

On display, if selected, set the checkbox hidden to NO:

UIImageView *checkbox = [cell.accessoryView viewWithTag:CHECKBOX_TAG];
if(selected){
    checkbox.hidden = NO;
}else{
    checkbox.hidden = YES;
}

Upvotes: 1

Abhishek
Abhishek

Reputation: 2253

Make a button and add it to your acceessoryView: and use it like a check box... this will resolve your problem

Upvotes: 0

Nuzhat Zari
Nuzhat Zari

Reputation: 3408

You can achieve this by using button.Create a button in cell with unchecked checkbox image and when user click on this button change the image of the button to check.

Upvotes: 0

Pfitz
Pfitz

Reputation: 7344

If you want a UIKit use accessoryType property of a UITableViewCell.

@property(nonatomic) UITableViewCellAccessoryType accessoryType

If you really want a custom one use accessoryView.

@property(nonatomic, retain) UIView *accessoryView

Upvotes: 0

Related Questions