我正在从表格视图中删除单元格并按照我正在使用的代码实现滑动删除:
#pragma mark -
#pragma mark Table View Data Source Methods
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:animated];
[addTagTableView setEditing:editing animated:YES];
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleDelete;
}
//Updating the data-model array and deleting the row
- (void)tableView:(UITableView *)tv commitEditingStyle: (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
// If row is deleted, remove it from the list.
if (editingStyle == UITableViewCellEditingStyleDelete)
{
[self.tagsArray removeObjectAtIndex:indexPath.row];
[self.addTagTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
这允许我实现刷卡删除,但我想简单的减去红色按钮删除,如何实现呢?
答案 0 :(得分:7)
- (void)viewDidLoad {
self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
使用此代码,您的应用中会有一个编辑按钮。如果按此按钮,将自动显示“红色减号”:)
答案 1 :(得分:3)
您可以放置UIButton并将其连接到IBAction。在IBAction编写中,您将能够按照您的要求进行编写。
-(IBAction)editTableForDeletingRow
{
[addTagTableView setEditing:editing animated:YES];
}