How to disable user interaction with cell in uitableview

10,928

Setting UserinteractionEnabled will not prevent the delegate method tableView: didSelectRowAtIndexPath: from being called, so you need to keep track of the number of times didSelectRowAtIndexPath has been called for the row that contains your tableViewCell, in this case it is once, and run the

[self performSelectorInBackground:@selector(youtubeFeedMore) withObject:nil];

if the row has been tapped only once.

For example:

@property (assign) BOOL enableLoadMoreCell;

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
 {
   //Load more json data if loadmore cell tapped
if (indexPath.row == self.videos.count && self.enableLoadMoreCell == YES) {
   self.enableLoadMoreCell = NO;

   self.loadCell.userInteractionEnabled = NO;
   self.loadCell.title.text = @"loading...";

//Activity indicators for loadmore cell
  [self.loadCell.loadMoreActivityIndicator startAnimating];
  [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

  [self performSelectorInBackground:@selector(youtubeFeedMore) withObject:nil];
}


}

-(void)youtubeFeedMoreSelectorEnded {
  ....
Your Code
   self.enableLoadMoreCell = YES;

}

Share:
10,928
Guferos
Author by

Guferos

Updated on June 04, 2022

Comments

  • Guferos
    Guferos almost 2 years

    I have simple UITableView for youtube movies. Cells are loading from array and when I fetch first 10 movies from youtube API last cell is 'load more' cell. When user tap on 'load more' cell it will fetch and load next 10 movies. Everything is fine except when I will tap very quick twice or more times on 'load cell' before it will refresh my table with new array, than I am having strange behaviour (all cells with movies disappearing and I have a lot 'load more' cells spread within table rows)so my table is totally messed up. Problem doesn't exist if I'am tapping 'load more' cell gently with only one tap.

    I have set userInteractionEnabled to NO after my cell is tapped but it didn't help. Can someone tell me what I am doing wrong? Here is my code:

        - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
     {
       //Load more json data if loadmore cell tapped
        if (indexPath.row == self.videos.count) {
           self.loadCell.userInteractionEnabled = NO;
           self.loadCell.title.text = @"loading...";
    
        //Activity indicators for loadmore cell
          [self.loadCell.loadMoreActivityIndicator startAnimating];
          [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    
          [self performSelectorInBackground:@selector(youtubeFeedMore) withObject:nil];
      }
    
    
     }
    
  • Guferos
    Guferos about 11 years
    Simple and effective. Thanks.
  • Adam Carter
    Adam Carter over 8 years
    Hi, I realise this is from nearly three years ago… but, is there any Apple docs that say Setting UserinteractionEnabled will not prevent the delegate method tableView: didSelectRowAtIndexPath: from being called? I want to implement this but am a little tentative that my code may break in the future! Thanks :)
  • Ronny Webers
    Ronny Webers over 8 years
    ok - but how doe you know when loading is done? cellForRowAtIndexPath is called a number of times, but you cannot really know which is the last one - there's no such callback as 'didFinishReloading' I guess?