Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 561
Steve Gear Avatar asked Dec 01 '22 03:12

Steve Gear


1 Answers

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

like image 53
Sudhanshu Avatar answered Dec 04 '22 05:12

Sudhanshu