我正在尝试在Storyboard中的UIView中实现TableView。 这就是我所取得的成就:
现在我想要编辑按钮,如果按下,则准备要删除的表行。 我按下栏上的编辑按钮:
//add edit button
[buttons addObject:self.editButtonItem];
此外,我将tableview委托和数据源设置为主视图,并触发事件。但是,如何告诉编辑按钮表格的行必须是可删除的?
提前谢谢你, yassa
答案 0 :(得分:2)
有这个委托tabelView方法:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
//some other bookkeeping stuff
}
按下时为“编辑”按钮添加了代码。将“切换编辑”重命名为适合您需要的任何内容。
- (IBAction)toggleEdit:(id)sender //this method should get called when Edit is pressed
{
[self.tableView setEditing:!self.tableView.editing animated:YES];
//The if ... else part is optional. You might need to make some change to fit your's.
// if (self.tableView.editing)
// [self.navigationItem.rightBarButtonItem setTitle:@"Done"];
// else
// [self.navigationItem.rightBarButtonItem setTitle:@"Delete"];
}