gpt4 book ai didi

ios - dequeueReusableCellWithIdentifier 返回相同索引路径的不同单元格

转载 作者:行者123 更新时间:2023-11-28 23:59:23 24 4
gpt4 key购买 nike

我试图了解出了什么问题,因为当我进行 TableView 更新并调用 cellForRowAtIndexPath 时, dequeueReusableCellWithIdentifier 无法取回我需要的单元格。

这只是一个 TableView 更新,具有绝对相同的indexPath,并且 dequeueReusableCellWithIdentifier 在第一次更新时返回 nil 并为其创建另一个单元。这很糟糕,因为每个更新方法都会调用两次,这会导致图像闪烁

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

cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if (cell == nil)
cell = [[cellClass alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];

if ([cellClass isEqual:[ATTimeLineMealCell class]]) {
NSLog(@"table view: %@",tableView);
NSLog(@"CELL DATA: %@",cell);
NSLog(@"Row: %ld , section: %ld",indexPath.row,indexPath.section);
}

}

- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{

NSLog(@"table view: %@",tableView);
NSLog(@"CELL DATA UPDATE:%@",cell);
}

流量:插入新单元格然后在单元格上重新加载(不是 reloadData)

和日志:

> 2018-04-26 15:53:26.214828+0200 Ate[6956:2981607] table view:
> <ATQueryTableView: 0x10482a600; baseClass = UITableView; frame = (0 0;
> 375 667); clipsToBounds = YES; gestureRecognizers = <NSArray:
> 0x1c044f960>; layer = <CALayer: 0x1c00362a0>; contentOffset: {0,
> -292}; contentSize: {375, 747}; adjustedContentInset: {292, 0, 0, 0}> 2018-04-26 15:53:26.215271+0200 Ate[6956:2981607] CELL DATA:
> <ATTimeLineMealCell: 0x1040aa800; baseClass = UITableViewCell; frame =
> (0 0; 375 44); layer = <CALayer: 0x1c4437de0>> 2018-04-26
> 15:53:26.215290+0200 Ate[6956:2981607] Row: 1 , section: 0 2018-04-26
> 15:53:26.216296+0200 Ate[6956:2981607] table view: <ATQueryTableView:
> 0x10482a600; baseClass = UITableView; frame = (0 0; 375 667);
> clipsToBounds = YES; gestureRecognizers = <NSArray: 0x1c044f960>;
> layer = <CALayer: 0x1c00362a0>; contentOffset: {0, -292}; contentSize:
> {375, 747}; adjustedContentInset: {292, 0, 0, 0}> 2018-04-26
> 15:53:26.216409+0200 Ate[6956:2981607] CELL DATA
> UPDATE:<ATTimeLineMealCell: 0x1040aa800; baseClass = UITableViewCell;
> frame = (0 80; 375 120); autoresize = W; layer = <CALayer:
> 0x1c4437de0>>
>
> 2018-04-26 15:53:28.456177+0200 Ate[6956:2981607] table view:
> <ATQueryTableView: 0x10482a600; baseClass = UITableView; frame = (0 0;
> 375 667); clipsToBounds = YES; gestureRecognizers = <NSArray:
> 0x1c044f960>; layer = <CALayer: 0x1c00362a0>; contentOffset: {0, 80};
> contentSize: {375, 747}; adjustedContentInset: {315, 0, 0, 0}>
> 2018-04-26 15:53:28.456308+0200 Ate[6956:2981607] CELL DATA:
> <ATTimeLineMealCell: 0x104162a00; baseClass = UITableViewCell; frame =
> (0 0; 375 44); layer = <CALayer: 0x1c4437bc0>> 2018-04-26
> 15:53:28.456387+0200 Ate[6956:2981607] Row: 1 , section: 0 2018-04-26
> 15:53:28.457095+0200 Ate[6956:2981607] table view: <ATQueryTableView:
> 0x10482a600; baseClass = UITableView; frame = (0 0; 375 667);
> clipsToBounds = YES; gestureRecognizers = <NSArray: 0x1c044f960>;
> layer = <CALayer: 0x1c00362a0>; contentOffset: {0, 80}; contentSize:
> {375, 747}; adjustedContentInset: {315, 0, 0, 0}> 2018-04-26
> 15:53:28.457191+0200 Ate[6956:2981607] CELL DATA
> UPDATE:<ATTimeLineMealCell: 0x104162a00; baseClass = UITableViewCell;
> frame = (0 80; 375 120); autoresize = W; layer = <CALayer:
> 0x1c4437bc0>>
>
>
> 2018-04-26 15:53:29.814609+0200 Ate[6956:2981607] table view:
> <ATQueryTableView: 0x10482a600; baseClass = UITableView; frame = (0 0;
> 375 667); clipsToBounds = YES; gestureRecognizers = <NSArray:
> 0x1c044f960>; layer = <CALayer: 0x1c00362a0>; contentOffset: {0, 80};
> contentSize: {375, 747}; adjustedContentInset: {315, 0, 0, 0}>
> 2018-04-26 15:53:29.816399+0200 Ate[6956:2981607] CELL DATA:
> <ATTimeLineMealCell: 0x1040aa800; baseClass = UITableViewCell; frame =
> (0 80; 375 120); hidden = YES; autoresize = W; layer = <CALayer:
> 0x1c4437de0>> 2018-04-26 15:53:29.816420+0200 Ate[6956:2981607] Row: 1
> , section: 0 2018-04-26 15:53:29.816792+0200 Ate[6956:2981607] table
> view: <ATQueryTableView: 0x10482a600; baseClass = UITableView; frame =
> (0 0; 375 667); clipsToBounds = YES; gestureRecognizers = <NSArray:
> 0x1c044f960>; layer = <CALayer: 0x1c00362a0>; contentOffset: {0, 80};
> contentSize: {375, 747}; adjustedContentInset: {315, 0, 0, 0}>
> 2018-04-26 15:53:29.816849+0200 Ate[6956:2981607] CELL DATA
> UPDATE:<ATTimeLineMealCell: 0x1040aa800; baseClass = UITableViewCell;
> frame = (0 80; 375 120); autoresize = W; layer = <CALayer:
> 0x1c4437de0>>

从日志看来,更新到来时,它会为同一索引路径再创建一个单元格:

  • 原始单元内存地址:0x1040aa800
  • 新生成的,但为什么??内存地址:0x104162a00

最佳答案

cellForRowAtIndexPath get called, the dequeueReusableCellWithIdentifier not getting back the cell what I need

您误解了表格 View 的工作原理。细胞被重复使用。同一单元格对象可能现在在一行中使用,现在在另一行中使用。同一行现在可能被一个单元格对象占据,现在又被另一个单元格对象占据。没有信件。这完全不取决于您,并且完全不相关,您为特定索引路径获得的单元格。您的工作是配置您获得的任何单元格对象,使其对于该索引路径是正确的

关于ios - dequeueReusableCellWithIdentifier 返回相同索引路径的不同单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50045088/

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