gpt4 book ai didi

iphone - 滚动 TableView 时自定义标签值消失

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:42:22 24 4
gpt4 key购买 nike

我是 iPhone 新手。当我滚动表格 View 时,我的 cutomcell label 值消失了。

当我点击那个单元格时它再次出现。

谁能帮帮我?

提前致谢。

//table view in view controller created in xib


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

{

static NSString *CellIdentifier = @"ListOfProductsCell";

ListOfProductsCell *cell = (ListOfProductsCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

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

productItemDit=[productListArry objectAtIndex:indexPath.row];
NSString *offerStr= [NSString stringWithFormat:@"%.2f",[[productItemDit objectForKey:@"offer"] floatValue]];
NSString *fullCostStr=[[currencyCodeStr stringByAppendingString:@" "] stringByAppendingString:offerStr];
NSLog(@"%@",fullCostStr);
cell.itemCostLbl.text=fullCostStr;

} else {
cell.itemStepper = (UIStepper *) [cell viewWithTag:2];
cell.itemAddedLbl =(UILabel*)[cell viewWithTag:1];

}

if (tableView == self.searchDisplayProduct.searchResultsTableView) {
searchProductItemDit=[searchProductListArry objectAtIndex:indexPath.row];
NSLog(@"searchdit:%@",searchProductItemDit);
cell.itemNameLbl.text= [searchProductItemDit objectForKey:@"name"];
self.searchDisplayProduct.searchResultsTableView.separatorColor=[UIColor colorWithRed:200.0 green:0.0 blue:0.0 alpha:1.0];
} else {
productItemDit=[productListArry objectAtIndex:indexPath.row];
NSLog(@"dit:%@",productItemDit);
cell.itemNameLbl.text=[productItemDit objectForKey:@"name"];
}

cell.itemAddedLbl.text = [[NSString alloc] initWithFormat:@"%d",itemCount];

cell.itemImg.image = [UIImage imageNamed:@"profp.jpg"];

return cell;

}

最佳答案

这样解决了

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

{

static NSString *CellIdentifier = @"ListOfProductsCell";

ListOfProductsCell *cell = (ListOfProductsCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

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

} else {
cell.itemStepper = (UIStepper *) [cell viewWithTag:2];
cell.itemAddedLbl =(UILabel*)[cell viewWithTag:1];

}

if (tableView == self.searchDisplayProduct.searchResultsTableView) {
cell.itemNameLbl.text= [[searchProductListArry objectAtIndex:indexPath.row] objectForKey:@"name"];
} else {
cell.itemNameLbl.text=[[productListArry objectAtIndex:indexPath.row] objectForKey:@"name"];
}

cell.itemCostLbl.text=[NSString stringWithFormat:@"%@ %.2f", currencyCodeStr , [[[productListArry objectAtIndex:indexPath.row] objectForKey:@"offer"] floatValue]];

cell.itemAddedLbl.text = [[NSString alloc] initWithFormat:@"%d",itemCount];

cell.itemImg.image = [UIImage imageNamed:@"profp.jpg"];

return cell;

}

关于iphone - 滚动 TableView 时自定义标签值消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17316026/

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