HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了iOS:UITableView在滚动速度过快时会混合数据大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经将uITableViewCell子类化为它添加自定义外观.在myTableViewCell的init级别,我添加了4个子视图:UI ImageView和三个UILabel.所有4个子视图都分配了不同的标记.

在cellForRowATindexPath方法中,我要么创建一个新单元格,如果它最初不可用,要么重用可用的单元格并将正确的文本分配给ui标签.

我遇到的问题是,如果我尝试超快速滚动,那么数据会搞砸,但是如果我上下滚动得更慢,那么一切正常.

有什么想法吗??

以下是代码

- (myTableViewCell *)tableView:(UITableView *)tableView cellForRowATindexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"itemListTableViewCell";
myTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

DisplayableEntity *displayableEntity = [self.fetchedResultsController objectATindexPath:indexPath];

if( ! cell ) {
    cell = [[myTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reusEIDentifier:CellIdentifier];

    [self tableView:tableView appearanceForCell:cell withEntity:displayableEntity];
} else {

    UIImageView *imageView = (UIImageView *) [cell viewWithTag:IMAGEVIEW_TAG];
    imageView.image = [UIImage imagenamed:displayableEntity.displayImagename];

    UILabel *titleLabel = (UILabel *) [cell viewWithTag@R_527_6964@VIEW_TAG];
    titleLabel.text = displayableEntity.entityName;

    UILabel *itemDescription = (UILabel *) [cell viewWithTag:DESCRIPTION_TAG];
    itemDescription.text = displayableEntity.entityDesctiption;
  }
}

// some code removed to make it brief
- (void)tableView:(UITableView *)tableView appearanceForCell:(myTableViewCell *)cell withEntity:(DisplayableEntity *)entity {

    // cell image view
    UIImageView *cellImageView = [[UIImageView alloc] initWithImage:[UIImage imagenamed:[entity displayImagename]]];
    [cellImageView setTag:IMAGEVIEW_TAG];
    [cell addSubview:cellImageView];

    // adding entity name label    
    UILabel *itemtitlename = [self itemtitlenameLabelWithFrame:itemnameLabelRect itemname:[entity entityName]];
    [itemtitlename setTag@R_527_6964@VIEW_TAG];
    [cell addSubview:itemtitlename];

    // adding 'assigned to' label right under the item name label
    UILabel *itemDescriptionLabel = [self itemDescriptionLabelWithFrame:descriptionLabelFrame itemDescription:[entity entityDesctiption]];
    [itemDescriptionLabel setTag:DESCRIPTION_TAG];
    [cell addSubview:itemDescriptionLabel];
}

解决方法

我在tableView中看到了一些麻烦:cellForRowATindexPath:logic
它应该是:

>出列单元格
>如果单元格无法出列 – 请创建新单元格
>设置所有单元格属性

我的意思是这样的

- (myTableViewCell *)tableView:(UITableView *)tableView cellForRowATindexPath:(NSIndexPath *)indexPath 
{
    static NSString *CellIdentifier = @"itemListTableViewCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reusEIDentifier:CellIdentifier];
    } // <-- Note there is no else,we should reset properties in both cases

    NsmanagedObject *managedObject = [_fetchedResultsController objectATindexPath:indexPath];

    cell.textLabel.text = [managedObject valueForKey:@"text"];
    cell.imageView.image = [managedObject valueForKey:@"image"];

    return cell;
}

大佬总结

以上是大佬教程为你收集整理的iOS:UITableView在滚动速度过快时会混合数据全部内容,希望文章能够帮你解决iOS:UITableView在滚动速度过快时会混合数据所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。