美文网首页
遍历uitableview所有cell,判断是否选中该cell

遍历uitableview所有cell,判断是否选中该cell

作者: 策马鞭程 | 来源:发表于2016-07-02 17:28 被阅读0次

注意:只能取出看得见的cell

    for (NSInteger i=0; i<self.tempDatas.count; i++) {
        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
        UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
        if (cell.selected)
            ZLLog(@"选中:%zi",indexPath.row);
    }

用于系统多选cell操作


Paste_Image.png

iOS不提倡遍历全部cell,从抛给开发者的API就可以看出来,就给一个visiblecells方法,不让你轻松的拿到全部cell,优化内存使用的极佳方案。

非要遍历全部cell怎么办?
//只返回可见的cell

  • (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath
    //只返回当前不可见的cell
  • (UITableViewCell *)dequeueReusableCellWithIdentifier:(NSString *)identifier
    两种方法加一起用,就OK了。

相关文章

网友评论

      本文标题:遍历uitableview所有cell,判断是否选中该cell

      本文链接:https://www.haomeiwen.com/subject/wfmqjttx.html