滚动后,TableView数据消失

时间:2014-01-27 09:18:48

标签: ios iphone uitableview

Code :

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

{
     static NSString *str=@"cellidentifier";

    customCell *cell=(customCell *)[tableView dequeueReusableCellWithIdentifier:str];

    if(cell == nil)
    {
       NSArray *value= [[NSBundle mainBundle]loadNibNamed:@"customCell" owner:self options:nil];

        cell=[value objectAtIndex:0];
    }


    [cell setValue:[arr objectAtIndex:indexPath.row]];

    return cell;
}

customCell.h

-(void)setValue:(NSString*)val;

customCell.m
-(void)setValue:(NSString *)val
{
    lbl.text=val;
}

我用customCell创建了一个UITableView。它运行正常。当我向上滚动时,tableview中的数据正在消失并且看起来是空的。代码有什么问题? 任何帮助都会表示赞赏。enter image description here

2 个答案:

答案 0 :(得分:2)

试试这个。

在自定义单元格中,您必须重新签名“identifier”才能在.xib文件中重用此单元格

resign "Indentifier" in nib

答案 1 :(得分:0)

尝试使用cellForRowAtIndexPath中的以下代码。

if ([cell.contentView subviews]){
        for (UIView *subview in [cell.contentView subviews]) {
            [subview removeFromSuperview];
        }
    }

希望它对你有所帮助。

相关问题