How To Implement simple delete(with red minus button) in UITableViewCell
I'm deleting cell fr开发者_运维知识库om table view and it implement swipe delete, following code I'm using:
#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];
}
}
This allows me to implement swipe delete, but I want simple minus red button delete, how to achieve that?
- (void)viewDidLoad {
self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
With this code, there is an edit button in your app. If you press this button, the "red minus" appears automatically :)
You can put UIButton and wire up it to IBAction. In IBAction write so you will be able to do as per your requirement.
-(IBAction)editTableForDeletingRow
{
[addTagTableView setEditing:editing animated:YES];
}
精彩评论