gpt4 book ai didi

ios - 在 UITableView 中加载多条记录

转载 作者:行者123 更新时间:2023-11-29 02:56:26 24 4
gpt4 key购买 nike

我以这种方式加载 UITableView:

- (UITableViewCell *)tableView:(UITableView *)tableViewLocal cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";
CustomTableViewCell *cell = [tableViewLocal dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[CustomTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}

for(UIView *subview in cell.contentView.subviews)
{
[subview removeFromSuperview];
}


UIImage* img;
UIImageView *imv = [[UIImageView alloc]initWithFrame:CGRectMake(5, 5, 60, 60)];


if(isFiltered == TRUE){
cell.textLabel.text = [filteredTableData objectAtIndex:indexPath.row];
cell.textLabel.font = [UIFont systemFontOfSize:14];
}

if(isFiltered == FALSE){
cell.textLabel.text = [itemArray objectAtIndex:indexPath.row];
cell.textLabel.font = [UIFont systemFontOfSize:14];
cell.detailTextLabel.text = [NSString stringWithFormat:@"date added: %@", [DKStoreManager dateFileWasCreatedWithFileName:[itemArray objectAtIndex:indexPath.row] inFolderNumber:[_FolderCode intValue] forUser:[_PassedUserID intValue] andType:_FolderType]];
}

NSData* data = [DKStoreManager loadFileWithName:[itemArray objectAtIndex:indexPath.row] forFolderNumber:[_FolderCode intValue] forUser:userID andType:_FolderType];
img = [[UIImage imageWithData:data] cropToSize:CGSizeMake(320, 320) usingMode:NYXCropModeCenter];
imv.image = img;
[cell.contentView addSubview:imv];


cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

return cell;
}

如您所见,我有一个包含所有文件名称的 itemArray,对于每个单元格,我以这种方式加载相对的 NSData:

NSData* data = [DKStoreManager loadFileWithName:[itemArray objectAtIndex:indexPath.row] forFolderNumber:[_FolderCode intValue] forUser:userID andType:_FolderType];

由于它还加载图像(并且可能有超过 300 个单元格),因此 UI 会释放。

我尝试使用此链接的已接受答案仅加载可见单元格:

tableView: cellForRowAtIndexPath: get called not only for visible cells?

但是所有的单元格都是同时加载的。我不知道该怎么做...

最佳答案

cellForRowAtIndexPath 在 tableView 重新加载以及用户滚动时被调用。 UI 卡住可能是由于您的调用

for(UIView *subview in cell.contentView.subviews)
{
[subview removeFromSuperview];
}

UIImageView *imv = [[UIImageView alloc]initWithFrame:CGRectMake(5, 5, 60, 60)];

这意味着每次用户滚动时,您都在遍历所有 subview 并删除它们,同时分配 UIimageView,这不是显示内容的好方法。您可以使用 tableViewCell 的默认 imageView 属性来显示您的图像。得到你的形象后就说

cell.imageView.image = img;

关于ios - 在 UITableView 中加载多条记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23854454/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com