gpt4 book ai didi

ios - 在 TableView 的自定义单元格中隐藏/显示标签

转载 作者:行者123 更新时间:2023-11-28 19:31:35 25 4
gpt4 key购买 nike

我在 TableView 中有以下单元格。

最初,我为 Promotion 标签分配高度 0 及其硬编码值 $10。

每当用户点击 Promotion 按钮时,我将高度调大以显示 Promotion 及其值并分配高度 30

但是,我看到的唯一变化是,单元格的高度越来越大,第一个和第二个标签之间的空间越来越大,但我看不到promotion label

这是我的代码:

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

static NSString *cellLastIdentifier = @"lastcell";
LastTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellLastIdentifier];
if (cell == nil)
cell = [[LastTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellLastIdentifier];
cell.subTotalLbl.text = [NSString stringWithFormat:@"$ %.02f", subtotal ];
cell.salesLbl.text = [NSString stringWithFormat:@"+$ %.02f", tax ];
if(isPromotionApplied)
{
cell.promotionLabelHeight.constant = 30;
cell.promotionValueLblHeight.constant = 30;
cell.promotionValueLbl.text = @"120";
}
return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if(isPromotionApplied)
return 140.0;
else
return 100.0;
}

- (void)applyPromoCode : (double)percent
{
isPromotionApplied = YES;
NSIndexPath* rowToReload = [NSIndexPath indexPathForRow:[sharedData.orderItems count] inSection:0];
NSArray* rowsToReload = [NSArray arrayWithObjects:rowToReload, nil];
[self.checkOutTableView reloadRowsAtIndexPaths:rowsToReload withRowAnimation:UITableViewRowAnimationFade];
}

LastTableViewCell Storyboard

enter image description here

最佳答案

检查您的销售税标签应具有对促销标签的垂直底部约束以及促销标签应具有对自定义单元格的垂直底部约束的约束。

现在创建一个 IBOutlet 的促销标签高度约束,而不是 show hide 将高度设置为 0 和 20

这是一个简短的演示 https://github.com/harshalrj25/stackoverFlowAnswers

关于ios - 在 TableView 的自定义单元格中隐藏/显示标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43751028/

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