问题描述
||
我正在从表格视图中删除单元格,并实现了滑动删除功能,下面是我正在使用的以下代码:
#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];
}
}
这允许我实现滑动删除,但是我想要简单的减红色按钮删除,如何实现呢?
解决方法
您可以放置UIButton并将其连接到IBAction。在IBAction中编写,这样您就可以根据需要进行操作。
-(IBAction)editTableForDeletingRow
{
[addTagTableView setEditing:editing animated:YES];
}
,- (void)viewDidLoad {
self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
使用此代码,您的应用程序中将有一个编辑按钮。如果按此按钮,\“红色减号\”将自动出现:)