How can I change UITableViewCell using UIButton?
I am new to iPhone programming and am stuck with a situation.
The situation is that I want the UITableView to enter edit mode on a click of the UIButton. When entering edit mode, I should have a checkbox in each cell. And I wanted to change the images of checked cells if I click the UIToolBarButton.
How can I achieve this. Any help would be appreciated.
source to share
Like lnafziger said to enter edit mode
[self.tableview setEditing:YES animated:YES];
in a function connected to your button.
To show checkboxes in cells when the table is in edit mode, add these lines to viewDidLoad
:
[self.tableView setAllowsSelectionDuringEditing:YES];
[self.tableView setAllowsMultipleSelectionDuringEditing:YES];
Then to make your UIBarButtonItem change the images, add a for loop with an array [self.tableView indexPathsForSelectedRows]
and change the image of each cell like this:
NSArray *paths = [self.tableView indexPathsForSelectedRows];
for (NSIndexPath *path in paths) {
UITableViewCell *cell = (UITableViewCell *)[self.tableView cellForRowAtIndexPath:path];
//change cell.imageView image
}
source to share