2

我有用于 youtube 电影的简单 UITableView。单元格从数组加载,当我从 youtube API 获取前 10 部电影时,最后一个单元格是“加载更多”单元格。当用户点击“加载更多”单元格时,它将获取并加载接下来的 10 部电影。一切都很好,除非我在“负载单元”上快速点击两次或更多次,然后它会用新数组刷新我的表格,而不是我有奇怪的行为(所有单元格的电影都消失了,我有很多“负载更多”单元格分布在表格行中)所以我的表格完全乱了。如果我轻按一下“加载更多”单元格,则不存在问题。

在点击我的单元格后,我已将 userInteractionEnabled 设置为 NO,但它没有帮助。有人可以告诉我我做错了什么吗?这是我的代码:

    - (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 的次数,在这种情况下是一次,然后运行

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

如果该行仅被点击一次。

例如:

@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

如何确保任何时候只有一个 loadMore 请求在运行?然后您不需要阻止双击 - 只需记住已发送加载更多请求,并在请求返回或超时后重置标记。

于 2013-02-19T21:06:15.520 回答