gpt4 book ai didi

ios - TableView Multiple Prototype Cell 和行数

转载 作者:行者123 更新时间:2023-11-29 12:24:22 26 4
gpt4 key购买 nike

我想在第一个原型(prototype)单元格中有多行;第二个单元格必须是静态的。

我尝试这样做,但我不能让第二个原型(prototype)单元格保持静态。我正在为单元格使用自定义类:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

DetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ss"];
if (cell.tag == 0)
return 8;
else if (cell.tag == 1)
return 1;

else
return 1;
}

只有第一个得到返回,我什至没有看到这两个按钮。我做错了什么?

最佳答案

首先,除非您指定 UITableView 使用静态单元格,否则您不能使用它们。并且您不能在单个表格 View 中混合使用原型(prototype)单元格和静态单元格。

根据您的要求,您应该创建两个原型(prototype)单元格,而不是将一个单元格作为静态单元格:

一个原型(prototype) -> 为你的动态单元格

第二个原型(prototype) -> 为你的静态单元格

现在按如下方式更改 TableView 数据源:

 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{
// suppose [self.dynamicArray count] = 8
//Adding 1 for your static cell

return [self.dynamicArray count] + 1;

}

假设,您想要显示带有第二个原型(prototype)(静态单元格表​​示)的最后一个单元格,然后将 cellForRowAtIndexPath 实现为:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row < [self.dynamicArray count] )
{
// normal dynamic logic here
NSString *cellIdentifier = @"DynamicCellID"
// dequeue and configure for [self.dynamicArray objectAtIndex:indexPath.row]
}
//this will be the last cell in which you want the second prototype cell acting as Static cell
else
{
// dequeue and configure my second prototype cell for indexPath.row
NSString *cellIdentifier = ... // id for one of my static cells
}
}

您可以使用相同的逻辑在 heightForRowAtIndexPath 方法中为两个原型(prototype)单元实现不同的高度。

关于ios - TableView Multiple Prototype Cell 和行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29693332/

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