Reputation: 205
I want to implement a UITableView
that when I press a button in my ViewController
, I can see the delete button on the right of the cell, but not the red minus circle on the the left of the cell.
Any ideas on this?
Upvotes: 7
Views: 3748
Reputation: 4208
Just an approach:
isDeleteEnabled
(or whatever you name it) to TRUE
UITableView
and in cellForRowAtIndexPath
check for that BOOL valueTRUE
then load the all the UITableViewCell
as custom cells
with delete button on it (You need to set the selector method for
deletion of a row)isDeleteEnabled
UITableView
and this time in cellForRowAtIndexPath
check the value of isDeleteEnabled
- which will be FALSE
. So, you need to load normal(or your original) UITableViewCells.I have done the very similar thing following this approach.
Also, I haven't posted the code for it for three reasons:
Upvotes: 4
Reputation: 20021
Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
//add code here for when you hit delete
}
}
Upvotes: -3
Reputation: 4652
that simple if you dont want the minus sign to appear, consider implementing you own solution than default one, insert a delete button and provide an animation to it, do as you require
Upvotes: 1
Reputation:
My idea, don't use button but u can swipe the cell to delete with the method:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
//Use actionsheet or deleteRowsAtIndexPaths
}
}
Upvotes: -2
Reputation: 571
You dont need a button action to trigger this. If you implement the following delegate you can directly swipe and delete the cell.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
//Delete the row
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
Upvotes: -2