小编use*_*173的帖子

UITableView将重复的标签添加到彼此之上

当我向上和向下滚动时,我的UITableView会在彼此的顶部添加重复的标签.因此,最后添加的标签会增加加速减速和崩溃的标签.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    UILabel *label;
    label = [[UILabel alloc] initWithFrame:nameFrame];
    [label setText:[name objectAtIndex:indexPath.row + indexPath.section]];
    [label setFont:[UIFont fontWithName:@"Helvetica" size:18]];
    [label setBackgroundColor:[UIColor clearColor]];
    [cell addSubview:label];
    [label release];

    label = [[UILabel alloc] initWithFrame:statusFrame];
    [label setText:[status objectAtIndex:indexPath.row + indexPath.section]];
    [label setFont:[UIFont fontWithName:@"Helvetica" size:18]];
    [label setBackgroundColor:[UIColor clearColor]];
    [label setTextAlignment:(UITextAlignmentRight)];
    [cell addSubview:label];
    [label release];
    return cell;
}
Run Code Online (Sandbox Code Playgroud)

iphone objective-c duplicates uitableview uilabel

3
推荐指数
1
解决办法
3479
查看次数

标签 统计

duplicates ×1

iphone ×1

objective-c ×1

uilabel ×1

uitableview ×1