真的需要帮助。我到处寻找,但仍无法找到答案。所以,当我用自定义单元格滚动我的UITableView时,每次看到它时都会重新创建单元格。因此,它显着降低了我的表现。自定义UITableViewCell重新创建自己
我的方法
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = @"CellWithViewForProduct";
ProductCell *cell = (ProductCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
ProductDataStruct *dataStruct = [self.arrayData objectAtIndex:indexPath.row];
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"productCell" owner:nil options:nil];
for(id currentObject in topLevelObjects)
{
if([currentObject isKindOfClass:[ProductCell class]])
{
cell = (ProductCell *)currentObject;
break;
}
}
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
formatter.roundingIncrement = [NSNumber numberWithDouble:0.01];
formatter.numberStyle = NSNumberFormatterDecimalStyle;
NSString *price = [formatter stringFromNumber:[NSNumber numberWithFloat:(dataStruct.price.floatValue * [[[NSUserDefaults standardUserDefaults] objectForKey:@"CurrencyCoefficient"] floatValue])]];
NSString *priceString = [NSString stringWithFormat:@"%@ %@", price, [[NSUserDefaults standardUserDefaults] objectForKey:@"Currency"]];
cell.productPrice.text = priceString;
cell.productDescription.text = [NSString stringWithFormat:@"%@", dataStruct.descriptionText];
cell.productTitle.text = [NSString stringWithFormat:@"%@", dataStruct.title];
if (dataStruct.hit.integerValue == 1)
{
[cell.productImage.layer addSublayer:[hitView layer]];
}
else
if (dataStruct.hit.integerValue == 2)
[cell.productImage.layer addSublayer:[newsItemView layer]];
if (!dataStruct.image)
{
if (self.tableView.dragging == NO && self.tableView.decelerating == NO && dataStruct.link)
{
[self startIconDownload:dataStruct forIndexPath:indexPath];
}
// if a download is deferred or in progress, return a placeholder image
//cell.productImage.image = [UIImage imageNamed:@"Placeholder.png"];
// if a download is deferred or in progress, return a loading screen
cell.productImage.alpha = 0;
[cell.productImageLoadingIndocator startAnimating];
}
else
{
if (self.didLoad)
{
cell.productImage.alpha = 0;
}
[cell.productImageLoadingIndocator stopAnimating];
cell.productImage.image = dataStruct.image;
[self imageAnimation: cell.productImage];
}
NSLog(@"WAZAAA");
return cell;
}
你说的“这是重新创建”的意思 - 这是什么重现呢?怎么样? – 2012-10-16 16:41:35
单元格不是“每次创建”的。他们创建一次。 – 2012-10-16 16:42:37
在表中我有40个元素。当我向下滚动时 - 消息出现80次 – NewObjective