Question

I have most IBOutlet on TableView Cell They cover cell swipe Left Action. Cell only a small amount of space trigger delete Action. Place Help me
How can add SwipeGestureRecognizer in IBOutlet on cell

Was it helpful?

Solution

First, add this:

   - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}

Then

  - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
    //remove the deleted object from your data source.
    //If your data source is an NSMutableArray, do this
    [self.dataArray removeObjectAtIndex:indexPath.row];
    [tableView reloadData]; // tell table to refresh now
  }
}

OTHER TIPS

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{

    if (editingStyle == UITableViewCellEditingStyleDelete)
    {
       NSString   *str  = @"are you sure you want to delete";
    UIAlertView *logoutAlert = [[UIAlertView alloc] initWithTitle:@"" message:str delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:@"Yes",nil];
    [logoutAlert setTag:indexPath.row];
    [logoutAlert show];
    }
}

in alertview delegate method if u have only one section

    -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

        if(buttonIndex == 1)
        {
               [tblView beginUpdates];
                [tblView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForRow:alertView.tag inSection:0], nil] withRowAnimation:UITableViewRowAnimationAutomatic];
                [tblView endUpdates];
                [tblView reloadData];   
 }

I think this is may not be your required answer, but please try once.

This code is for, suppose you are adding UITextField, UIButton, UILabel etc on cell. This method is detect only gesture recognizer on cell.

 - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
   if ([touch.view isDescendantOfView:yourLabel] ||[touch.view isDescendantOfView:yourTextview] || [touch.view isDescendantOfView:yourButton])
   {
       return NO;
   }
   return YES;
} 

you can add scrollview in your custom cell on swip use these method to delete.(i used for left swip to hide and delete here). set scrollView on full cell and IB in it.

 - (void)setSelected:(BOOL)selected animated:(BOOL)animated
    {
        [super setSelected:selected animated:animated];

        [self.scrollViewCell setContentSize:CGSizeMake(640.0f, self.scrollViewCell.contentSize.height)];
        [self.scrollViewCell setExclusiveTouch:YES];

        // Configure the view for the selected state
    }

    -(void)scrollViewDidScroll:(UIScrollView *)scrollView{

        float opacity = ( 180 - scrollView.contentOffset.x ) / 100.0;
        opacity = (opacity < 0? 0.2f : opacity>1? 1 : opacity);
        scrollView.layer.opacity = opacity;
    }
    -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
        int pageNum = (int)(scrollView.contentOffset.x / scrollView.frame.size.width);
        if(pageNum==1){
            [_delegate deleteTableViewCellAtRow:scrollView.tag];
        }
    }

Here delegate is your tableview controller.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top