我正在尝试设置一个我可以编辑的 UITableView。我实现了以下方法:
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
但我不确定如何将编辑链接到我的 UINavigationBar 中的编辑按钮。这是我的按钮项目:
UIBarButtonItem * leftButton = [[UIBarButtonItem alloc] initWithTitle:@"Edit"
style:UIBarButtonSystemItemEdit
target:nil
action:@selector(editButtonSelected:)];
我如何让它工作?
最佳答案
我仅使用标准编辑按钮就取得了很多成功:
self.navigationItem.leftBarButtonItem = self.editButtonItem;
您的代码的问题是您没有设置目标。如果 editButtonSelected: 选择器在您设置它的 View Controller 中,请像这样使用“self”:
UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:@"Edit" style:UIBarButtonSystemItemEdit target:self action:@selector(editButtonSelected:)];
关于iphone - 可编辑的 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4905173/