Reputation: 4367
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];
}
}
Upvotes: 2
Views: 11153
Reputation: 620
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;
}
Upvotes: 3
Reputation: 9346
How about making sure that there is only one loadMore request running at any time? Then you do not need to prevent double clicking - just remember that a load more request has been sent, and reset the marker once the request returns or times out.
Upvotes: 0
Reputation: 529
Set
[self.view setUserInteractionEnabled:NO];
when loading and then change it to
[self.view setUserInteractionEnabled:YES];
after loading is done
Upvotes: 0