2

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];
  }


 }
4

3 に答える 3

3

UserinteractionEnabledを設定しても、デリゲートメソッドtableView:didSelectRowAtIndexPath:が呼び出されるのを防ぐことはできないため、tableViewCellを含む行に対してdidSelectRowAtIndexPathが呼び出された回数(この場合は1回)を追跡し、

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

行が1回だけタップされた場合。

例えば:

@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;

}

于 2013-02-19T21:07:57.030 に答える
0

設定

[self.view setUserInteractionEnabled:NO]; 

ロード時に変更します

 [self.view setUserInteractionEnabled:YES]; 

ロードが完了したら

于 2013-02-19T21:02:40.973 に答える
0

常に 1 つの loadMore リクエストのみが実行されるようにするにはどうすればよいでしょうか? その後、ダブルクリックを防止する必要はありません。ただ、load more リクエストが送信されたことを覚えておいてください。リクエストが返されるかタイムアウトになったら、マーカーをリセットしてください。

于 2013-02-19T21:06:15.520 に答える