我有带有自定义单元格的动态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
(以及其他必需的“反向”配置)。
关于ios - 自定义TableView单元格中的标签在滚动后消失,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21810122/