Steve Gear
Steve Gear

Reputation: 749

How can we put a checkbox in uitableviewcell

I created list of todos. Now I want to put the checkbox for each one cell. When I mark it as checked, it can be marked and then we select delete button if we want, which is also in the same cell at right side and deleted, but I am not able to perform action like this.

Can anyone please help me?

Upvotes: 4

Views: 17472

Answers (3)

Sudhanshu
Sudhanshu

Reputation: 3960

@Chakradhar not a big issue you can do it very easily with or without using custom images.

In your didSelectRowAtIndexPath delegate try to check and set the UITableViewCellAccessory as per your condition.

This is the way in which there is no need to use extra images and you can checked for you particular selected cell:

if (//here you check)
{   // item needed - display checkmark
    cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{   // not needed no checkmark
    cell.accessoryType = UITableViewCellAccessoryNone;
}

Take this shopping tutorial and see didSelectRowAtIndexPath delegate method see how they had used the condition.

Edited as per your last comment: For custom accessory view look for Implement a Custom Accessory View For UITableView in iPhone

Good Luck!

Upvotes: 17

Swastik
Swastik

Reputation: 2425

You can actually add custom button with an unchecked image on your cell. On button action method you can change the image to checked & handle rest of the things you want to handle.

Upvotes: 0

visakh7
visakh7

Reputation: 26400

Use this

cell.accessoryType = UITableViewCellAccessoryCheckmark;

Upvotes: 2

Related Questions