如何使用UIButton编辑UITableViewCell?

Has*_*sam 3 uitableview uitoolbar ios xcode4.2

我是iPhone编程新手,陷入困境.

情况是我希望UITableView在UIButton点击进入编辑模式.进入编辑模式后,我应该在每个单元格上有一个复选框.如果我点击UIToolBarButton,我想更改已检查的单元格图像.

我怎样才能做到这一点.任何帮助,将不胜感激.

Jon*_*asG 5

就像lnafziger说进入编辑模式调用一样

[self.tableview setEditing:YES animated:YES];
Run Code Online (Sandbox Code Playgroud)

在连接到按钮的功能中.

要在表格处于编辑模式时显示单元格上的复选框,请将这些行添加到viewDidLoad:

[self.tableView setAllowsSelectionDuringEditing:YES];
[self.tableView setAllowsMultipleSelectionDuringEditing:YES];
Run Code Online (Sandbox Code Playgroud)

然后为您的UIBarButtonItem更改图像添加一个for循环与[self.tableView indexPathsForSelectedRows]数组,并更改每个单元格图像,如下所示:

NSArray *paths = [self.tableView indexPathsForSelectedRows];
for (NSIndexPath *path in paths) {
    UITableViewCell *cell = (UITableViewCell *)[self.tableView cellForRowAtIndexPath:path];
    //change cell.imageView's image
}
Run Code Online (Sandbox Code Playgroud)