gpt4 book ai didi

苹果手机 : uitableview : contents of a cell change on scrolling

转载 作者:行者123 更新时间:2023-11-29 13:49:04 25 4
gpt4 key购买 nike

我有一个数组,我用它来提供表格 View 中自定义单元格的内容我不知道出了什么问题,但是当我滚动 tableview 时,contants oc 单元格会动态变化

请帮我解决这个问题

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

static NSString *MyIdentifier = @"MyIdentifier";
MyIdentifier = @"tblCellView";
NSString *offendersImagePath = [self applicationDocumentsDirectory];
//NSLog(@"%@", dbPath);
offendersImagePath=[offendersImagePath stringByAppendingPathComponent:@"Images"];


CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if(cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
cell = aCustomCell;
aCustomCell=nil;
}

NSMutableArray *tempArray;//=[[NSMutableDictionary alloc] init];

tempArray=[offendersNamesList objectAtIndex:indexPath.row];
//NSLog(@"%d",indexPath.row);

offendersImagePath=[offendersImagePath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.jpg",[tempArray objectAtIndex:0]]];
NSLog(offendersImagePath);
[[cell offendersImageView] setImage:[UIImage imageWithContentsOfFile:offendersImagePath]];
[cell.offendersNameLbl setText:[tempArray objectAtIndex:1]];
[cell.offendersViolation setText:[tempArray objectAtIndex:2]];
//[tempDictionary release];

//[cell setLabelText:[arryData objectAtIndex:indexPath.row]];
return cell;

最佳答案

这类问题的典型问题是您没有在 cellForRowAtIndexPath 中正确设置单元格中的内容。当一个单元格滚出屏幕时,系统会将其转储到“回收队列”(我的术语)中。当新单元格滚动到屏幕上时,系统会在此回收队列中查找可以重复使用的单元格。
((CustomCell *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier];)
如果找不到,它会继续并从头开始构建一个全新的。在您的情况下,无论出于何种原因,您似乎都没有正确设置单元格内容,并且您看到的更改是未使用正确内容更新的回收单元格。

我不确定您到底哪里出错了,但是您用于新单元格的代码有点奇怪。它应该看起来更像这样:

if(cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}

关于苹果手机 : uitableview : contents of a cell change on scrolling,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5870367/

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