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

来源:互联网 发布:淘宝团购提醒在哪里 编辑:程序博客网 时间:2024/06/10 18:06

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

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

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

我把tableView里面的背景色设置为clearColor时,如果cell的行数超过一页的话,拖动时,发现里面的文字会出现重影,
本来已经被刷新的文字没有消失,和新的显示的文字重叠在一起。有没有什么办法去掉以前的文字?
ajuncgpcqz2010-08-27 09:31大家没碰到类似的问题吗
buan2010-08-27 10:30static 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

原创粉丝点击