简体   繁体   中英

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?

@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!

用这个

cell.accessoryType = UITableViewCellAccessoryCheckmark;

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM