objective-c - iOS 自定义tableView cell重用导致内容重复 问题 如何有效解决?急急急!!
大家讲道理
大家讲道理 2017-04-18 09:57:24
0
7
497

 [self.tableView registerNib:[UINib nibWithNibName:@"NewTaskCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:NewTaskCellId];

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NewTaskCell *cell = [self.tableView dequeueReusableCellWithIdentifier:NewTaskCellId forIndexPath:indexPath];
    if (!cell) {
        cell = [[NewTaskCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NewTaskCellId];
    }
    if (self.taskList.count > indexPath.row) {
        FindDisOrderInfoEntity *entity = [self.taskList objectAtIndex:indexPath.row];
        [cell setCellContentWith:entity];
    }
    return cell;
}
大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(7)
迷茫

Remove if (self.taskList.count > indexPath.row)
Cell is assigned normally
When the cell is added, refresh the table or refresh the new row

巴扎黑

You should first look at the number of your cells. Secondly, the concept of cells is containers. Reuse is just reusing containers. The decision lies with the data source

阿神

You have already registered using the registerNib method. There is no need to determine whether the cell is empty in the proxy method

小葫芦

Write this in the (UITableViewCell )tableView:(UITableView )tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath proxy method:

NewTaskCell *cell = [self.tableView dequeueReusableCellWithIdentifier:NewTaskCellId forIndexPath:indexPath];
FindDisOrderInfoEntity *entity = [self.taskList objectAtIndex:indexPath.row];       [cell setCellContentWith:entity];
return cell;
Ty80

Cell reuse, the previous state is reused, such as the UIButtonUILabel 如果在重用之前UIButton是高亮状态 UILabel上的text=@"label"那么重用之后,UIButton还是高亮状态,UILabeltext还是labelcell重用的时候会调用cellForRow方法。所以一般会在cellForRow里面重新赋值和改变状态。所以在cell里面有个默认的规则 就是如果有if 那一定要有else on the cell, otherwise the cell will become messy.

Ty80

After registration, you don’t have to judge whether the cell is empty, but there is nothing wrong with it. Why does your count need to be judged? I don’t understand. Maybe your array is not a data source? But it probably isn't your problem. If your "duplication of content" means that the controls on the cell are added repeatedly, then it should be [cell setCellContentWith:entity]; There may be something wrong with the method in this. It may be that you are Create the control here and add it. Reuse only refreshes the data, that is, only the assignment process does not create the control

迷茫

If the tableview doesn’t display much, it won’t be repeated if you don’t let it be reused. Also, after calling the registerNib method, the memory will always be in CELL

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template