gpt4 book ai didi

ios - 仅 TableView 第一行的自定义样式

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:39:24 26 4
gpt4 key购买 nike

我正在尝试为表格 View 的第一行设置不同的样式。

我正在通过以下代码执行此操作:

def tableView(table_view, cellForRowAtIndexPath: index_path)
data_row = @data[index_path.row]
puts index_path.row
if index_path.row == 0
cell = table_view.dequeueReusableCellWithIdentifier(ITEM_CELL_ID) || begin
rmq.create(ItemCell, :first_cell, reuse_identifier: ITEM_CELL_ID).get
end
else
cell = table_view.dequeueReusableCellWithIdentifier(ITEM_CELL_ID) || begin
rmq.create(ItemCell, :rest_cell, reuse_identifier: ITEM_CELL_ID).get
end
end
cell.update(data_row)
cell
end

问题

但是我得到了非常奇怪的行为。第一行确实有自定义样式....但是第 10 行和第 20 行也是如此!我不知道为什么会这样。第 2 - 9 行和第 11-19 行与第 0 行、第 10 行和第 20 行不同。

最佳答案

您需要为每种细胞类型使用不同的 ITEM_CELL_ID (reuseIdentifiers)。因此,:first_cell 样式单元格应具有与 :rest_cell 样式单元格不同的 reuseIdentifier 常量。这应该可以解决您的问题,因为您看到的是第一个单元格的内存在表格滚动时被一遍又一遍地重复使用。

关于ios - 仅 TableView 第一行的自定义样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23725281/

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