---
title: "uitableview  cell 数据重复"
author: "修博龙泉"
date: "2012-11-26T10:58:53Z"
tags: []
categories: ["移动开发"]
slug: "uitableview-cell"
draft: false
lastmod: "2013-04-09T15:07:15Z"
id: 1735208
url: "https://longquan.iteye.com/blog/1735208"
---

```java

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier];
    if (cell == nil) {
        cell = [[[uitableviewcell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }else{
        while ([cell.contentview.subviews lastobject] != nil) {
            [(uiview*)[cell.contentview.subviews lastobject] removeFromSuperview];  //删除并进行重新分配
        }
    }

```



```java

  NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier];
    if (cell == nil) {
        cell = [[uitableviewcell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    for (UIView *subView in cell.contentView.subviews) {
        [subview removefromsuperview];
    }


```