gpt4 book ai didi

ios - 仅在一个部分显示表格 View 页脚

转载 作者:行者123 更新时间:2023-11-29 02:10:43 24 4
gpt4 key购买 nike

我正在开发一个列出产品的应用程序。产品是节标题。如果您点击某个产品,它会展开以显示该部分的表格,并在该表格的单元格中对该产品进行修改。

我想要做的是为每个部分添加一个页脚,其中包含“添加到购物车”按钮。该页脚只应在产品展开时可见。如果我使用这个:

- (CGFloat)tableView:(UITableView*)tableView heightForFooterInSection:(NSInteger)section {
if (self.isOpen) {
return 35.0;
}
else {
return 0.0;
}
}

在您选择产品之前,页脚不会显示在任何产品部分,然后它会在所有产品上可见。有没有办法让它在一个 table 部分有一定的高度?我曾尝试通过修改检测表格中的最后一个单元格,但事实证明它确实存在问题。添加到购物车按钮将显示在随机行上。

编辑:这是检测最后一行的 cellForRow 方法:

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

... Custom Cell dequeue

// Currently only 3 rows for modifications, so 0-2, last one is 3 for Add to Cart
if(indexPath.row == 3){
cell.textLabel.text = @"Add to Cart";
cell.productName.text = @"";
cell.productDescription.text = @"";
}
else {
...Regular cell items
}
return cell;
}

最佳答案

您在其他部分中的 viewForFooter 方法是否也返回 nil ?

我们可能需要知道如何检查某个部分是否有 addToCart 按钮...但这是我的猜测:

- (CGFloat)tableView:(UITableView*)tableView heightForFooterInSection:(NSInteger)section {
if (self.isOpen && [self hasCartForSection:section]) {
return 35.0;
}
else {
// One table view style will not allow 0 value for some reason
return 0.00001;
}
}

- (UIView*)tableView:(UITableView*)tableView viewForFooterInSection:(NSInteger)section {
if (self.isOpen && [self hasCartForSection:section]) {
UIView *footerView = [UIView.alloc init];

// Build your footer

return footerView;
}

return nil;
}

- (BOOL)hasCartForSection:(int)section {
BOOL someCondition = NO;

// Do your check

if (someCondition) {
return YES;
}

return NO;
}

关于ios - 仅在一个部分显示表格 View 页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29313000/

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