我有带有自定义单元格的动态tableView。CustomCell .h文件如下所示:
@property (strong, nonatomic) IBOutlet UILabel *uslugaName; //I set retain doesn't work too
@property (strong, nonatomic) IBOutlet UILabel *howMuchPayLbl;
我的CellForRowAtIndexPathMethod:
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString * cellIdentifier = @"Cell";
myCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
/*
if (!cell)
cell = [[myCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
*/
if (indexPath.row !=15) {
cell.uslugaName.text =serviceNameArr[indexPath.row];
//окрашиваем ячейку в зависимости от активности услуги
if ([uslugaIsActiveArr[indexPath.row] isEqual: @"1"]) {
cell.backgroundColor = [UIColor blackColor];
cell.howMuchPayLbl.enabled = YES;
}
else {
cell.backgroundColor = [UIColor grayColor];
cell.howMuchPayLbl.enabled = NO;
}
if (![amountTmpArr[indexPath.row] isEqual: @"0"])
cell.howMuchPayLbl.text = [NSString stringWithFormat:@"Оплачиваю: %@ KZT", amountTmpArr[indexPath.row]];
}
else {
cell.uslugaName.font = [UIFont fontWithName:@"System Bold" size:16];
cell.uslugaName.text = [NSString stringWithFormat:@"ОБЩАЯ СУММА ОПЛАТЫ: %@", fullAmount];
cell.howMuchPayLbl.hidden = YES;
}
return cell;
}
我希望最后一行与其他行不同(为此:
如果(indexPath.row!= 15)
)。问题是-滚动cell.howMuchPayLb时消失。如果删除最后一行的特殊代码-一切正常,为什么会这样?
您的代码中有一条if else
语句,其中一个分支可以设置,cell.howMuchPayLbl.hidden = YES;
而另一分支则不能设置cell.howMuchPayLbl.hidden = NO;
。因此,一旦标签被隐藏,它将永远不会被隐藏。重用带有隐藏标签的单元格时,标签保持隐藏状态。
cell.howMuchPayLbl.hidden = NO;
在您的if
语句中添加(以及其他任何需要的“反向”配置)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句