-- tableView的cell背景设置为透明时,文字会重叠在一起 -

-- tableView的cell背景设置为透明时,文字会重叠在一起 -

http://www.cocoachina.com/bbs/simple/?t30484.html

tableView的cell背景设置为透明时,文字会重叠在一起

我把tableView里面的背景色设置为clearColor时,如果cell的行数超过一页的话,拖动时,发现里面的文字会出现重影,
本来已经被刷新的文字没有消失,和新的显示的文字重叠在一起。有没有什么办法去掉以前的文字?

ajuncgpcqz2010-08-27 09:31
大家没碰到类似的问题吗

buan2010-08-27 10:30
static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
        UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier];
        NSInteger section=[indexPath section];
        if(cell==nil)
        {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"SimpleTableIdentifiers"] autorelease];
        }

以前我也碰到过这样的情况,你tableView里面肯定还有其他的控件吧

ajuncgpcqz2010-08-27 15:22
是啊,里面有几个label和button

不过问题我已经解决了,解决方法如下:


-(UITableViewCell *)tableView:(UITableView *)tableView
        cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *RootViewControllerCell=@"RootViewControllerCell";
    
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:RootViewControllerCell];
    
    if(cell==nil)
    {
        cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault 
                                    reuseIdentifier:RootViewControllerCell] autorelease];        
        
        CGRect textValueRect=CGRectMake(90, 15, 150, 40);
        UILabel *textValue=[[UILabel alloc]initWithFrame:textValueRect];
        textValue.textColor=[UIColor whiteColor];
        textValue.tag=NameValueTag;
        textValue.backgroundColor=[UIColor clearColor];
        textValue.font=[UIFont boldSystemFontOfSize:18];    
        [cell.contentView addSubview:textValue];
        [textValue release];
    }
    
    NSUInteger row=[indexPath row];    
    
    UILabel *textName=(UILabel *)[cell.contentView viewWithTag:NameValueTag];        
    textName.text=[listData objectAtIndex:row];

       return cell;
}

要把label的定义部份放在if里面,这样就不会重复刷新了


r78z

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值