自定义UITableViewCells在滚动后重复行

www*_*com -3 iphone uitableview ios

我正在寻找解决方案......

码:

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

    NSString *CellIdentifier = @"ItemCardapio";
    NSString *nibName = @"ItemCardapioCell";

    ItemCardapioCell *cell = (ItemCardapioCell *) [self.restaurantsList dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) { 
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:nibName owner:self options:nil]; 
        cell = (ItemCardapioCell *)[nib objectAtIndex:0];

        [cell initCellWithRestaurant:@"" tipoRestaurante:@""];      
    }

    return cell;
}
Run Code Online (Sandbox Code Playgroud)

Ale*_*lan 5

我发现,如果细胞重复出现问题,那么当你把不应该放入的东西放进去时,问题就会发生if (cell == nil).

原因是如果您没有适当地更新单元格的某些方面,表格视图将最终使用不正确的重用单元格.

尝试采取任何直接改变你的细胞的东西if (cell == nil),它应该停止重复细胞的问题.