Reputation: 11
The swipe to delete a table cell does not work properly. I have to swipe really fast and multiple times for it to work. The below code works in ios 7. Can someone tell me what I would need to do to get this to work smoothly in ios 8?
@implementation SimpleTableCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
-(void)willTransitionToState:(UITableViewCellStateMask)state{
[super willTransitionToState:state];
if ((state & UITableViewCellStateShowingDeleteConfirmationMask) == UITableViewCellStateShowingDeleteConfirmationMask) {
for (UIView *subview in self.subviews) {
if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"]) {
UIImageView *deleteBtn = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 64, 33)];
[deleteBtn setImage:[UIImage imageNamed:@"deleteButton.png"]];
[[subview.subviews objectAtIndex:0] addSubview:deleteBtn];
}
}
}
}
@end
Upvotes: 1
Views: 703
Reputation: 41
I had the exact same issue. After a few hours, I finally figured that the problem was coming from my navigation controller containing a swipe gesture recognizer.
The native comment editing feature uses a Swipe GestureRecognizer, so if you have any gesture recognizer, don't forget to add this line in order to allow simultaneous gesture recognition !!
- (BOOL)gestureRecognizer:(UIPanGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UISwipeGestureRecognizer *)otherGestureRecognizer { return YES; }
I really hope that it will help, because it was driving me crazy...
Upvotes: 3
Reputation: 29161
This should be very straightforward (and works fine for me, in iOS 8...)
You just need to make sure your UITableView has this:
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// YES - we do want to enable "swipe to delete" on this row.
return YES;
}
...and this...
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
// Add some code to delete your row...
}
Do you have these two pieces in your code ?
Upvotes: 0