草庐IT

ios - dequeueReusableCellWithIdentifier 不起作用

coder 2023-09-30 原文

我想在 UITableview 中加载大约 6000 - 8000 行。我使用异步调用从服务器获取数据,当我获取数据时调用

[tableView reloadData]

This is to refresh the table view . But because of some reason my app gets stuck and freezes . When I debug , I found that cellforrowatindexpath is called 6000 times (on main thread) and dequeueReusableCellWithIdentifier always returns null .

- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath{
       CDTableRowCell *cell = nil;

        // Create and Resue Custom ViewCell
        static NSString *CellIdentifier = @"CellIdentifier";
        cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

        // got into render/theme objec 
        if(cell == nil){
            cell = [[CDTableRowCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
        }

// MODIFYING CELL PROPERTIES HERE FROM AN ARRAY
// NO HTTP CALLS 

}

此外,一旦我开始滚动,tableview 就会开始重用单元格,但在此之前我从来没有总是创建一个新单元格。 知道为什么会出现这种奇怪的行为吗???

最佳答案

这样试试,

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

    static NSString *CellIdentifier =@"Cell";

    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {

        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

}

return cell;

}

关于ios - dequeueReusableCellWithIdentifier 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12223274/

有关ios - dequeueReusableCellWithIdentifier 不起作用的更多相关文章

随机推荐