如何在 uitableview 中禁用用户与单元格的交互 [英] How to disable user interaction with cell in uitableview

查看:31
本文介绍了如何在 uitableview 中禁用用户与单元格的交互的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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


 }

推荐答案

设置 UserinteractionEnabled 不会阻止委托方法 tableView: didSelectRowAtIndexPath: 被调用,所以你需要跟踪 didSelectRowAtIndexPath 被调用的次数包含您的 tableViewCell 的行,在本例中为一次,然后运行 ​​

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.

例如:

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

}

这篇关于如何在 uitableview 中禁用用户与单元格的交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆