滚动后iOS UITableViewCell无法正确更新

时间:2015-08-21 07:56:15

标签: ios objective-c iphone uitableview

这就是我所拥有的:我有一个带有自定义UITableViewCell的TableView,它正在从MutableArray加载数据。

在我的cellForRow中:我调用代码用数组中的数据绘制子视图,当我向下滚动并向上滚动时,该子视图看起来非常错误,但每个标签看起来都是正确的......

我已经尝试了很多围绕谷歌的答案,但都没有解决它,我甚至把子视图放到阵列但也没有工作,抱歉我不能发布图像:(

NSMutableArray *mintHistoryList = //Array of Epin objects 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
// Configure the cell...

EPinObject *data;

if (indexPath.row < self.mintHistoryList.count && [[self.mintHistoryList objectAtIndex:indexPath.row] isKindOfClass:[EPinObject class]])
    {
        data = [self.mintHistoryList objectAtIndex:indexPath.row];
        UILabel *pinGeneratedDateLabel = (UILabel *)[cell viewWithTag:100];
        pinGeneratedDateLabel.text = data.pinGeneratedTime;

        UILabel *pinNumberLabel = (UILabel *)[cell viewWithTag:101];
        pinNumberLabel.text = data.pinCode;

        UILabel *pinOriginalLabel = (UILabel *)[cell viewWithTag:102];
        pinOriginalLabel.text = [NSString stringWithFormat:@"%@%@", [Common currencyFloatRemake:data.pinOriginalAmount],[Common currencyCodeToSymbol:data.pinCurrencyCode]];
        pinOriginalLabel.adjustsFontSizeToFitWidth=YES;
        pinOriginalLabel.minimumScaleFactor=0.5;

        UILabel *pinLeftLabel = (UILabel *)[cell viewWithTag:103];
        pinLeftLabel.text = [NSString stringWithFormat:@"%@%@ left", [Common currencyFloatRemake:data.pinLeftAmount],[Common currencyCodeToSymbol:data.pinCurrencyCode]];
        pinLeftLabel.adjustsFontSizeToFitWidth=YES;
        pinLeftLabel.minimumScaleFactor=0.5;

        //THIS PART

        UIView *circleView = (UIView *)[cell viewWithTag:104];
        [circleView addSubview:[Customview alloc]initWithOriginal:data.pinOriginalAmount andLeft:data.pinLeftAmount];  
    }

数组不会改变,其他标签也不会改变,只有子视图不正确

正确: https://drive.google.com/file/d/0BwtBKpSMH_eHUWRfMkpzOTFaTkE/view?usp=sharing

向下滚动: https://drive.google.com/file/d/0BwtBKpSMH_eHWkxmeDNGQUJvdnM/view?usp=sharing

1 个答案:

答案 0 :(得分:1)

我觉得问题在这里

UIView *circleView = (UIView *)[cell viewWithTag:104];
[circleView addSubview:[Customview alloc]initWithOriginal:data.pinOriginalAmount andLeft:data.pinLeftAmount];  

当你重复使用它时,它将包含2个circleView ... 您应该删除上一个,或重复使用circleView本身

PS图像无法使用,我收到错误403