向上滚动后,UITableview项变为粗体 [英] UITableview items becomes bold after scrolling up

查看:73
本文介绍了向上滚动后,UITableview项变为粗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,也许我太挑剔了.如果您看不到它,请提前道歉,但是在第二张图片中,该行上的项目被像素化了一点,或者好像一个单词放在了一个单词的顶部.这只会在我向上滚动表格视图后发生,否则,它类似于第一张图片.

Ok maybe I am being too picky. Apologies in advance if you cannot see it, but in the second pic, the item on the row is pixellated a bit, or as if a word was placed on top of a word. This only happens after I scroll up on the tableview, otherwise, it is similar to the first image.

第一张照片:

第二张图片(您可以在此处看到字体的不同):

Second pic (you can see the difference in the font here):

当我向上滚动时,它会变得更加大胆和细化.

it's a bit more bold and unrefined once I scroll up.

坦率地说,我不知道为什么. tableview正在正常加载.任何帮助,直觉或建议都会有很大的联系,即使它可以使我指向正确的领域.

I frankly have no idea why. The tableview is being loaded normally. Any help, hunch, or suggestion would be greatly associated, even if it can point me to the right area.

这是第二张图片的表格视图的代码.

Here is the code for the second image's tableview.

static NSString *CellIdentifier = @"OrderProductCell";

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

}

//cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];


//configure cell, display name and cost of each item
OrderProduct *p = [[order.items allObjects] objectAtIndex:indexPath.row];

UILabel *lableName=[[UILabel alloc]initWithFrame:CGRectMake(10, 16, 300, 20)];
lableName.backgroundColor=[UIColor clearColor];
lableName.font=[UIFont boldSystemFontOfSize:19];
[lableName setFont:[UIFont fontWithName:@"Arial-Bold" size:12.0]];
lableName.text=p.name;

//UILabel *counterNumber=[[UILabel alloc]initWithFrame:CGRectMake(10, 25, 300, 20)];
//counterNumber.backgroundColor=[UIColor clearColor];
//counterNumber.font=[UIFont systemFontOfSize:12];
//counterNumber.text=[NSString stringWithFormat:@"Scan time :%@",p.scannerCounter];
[cell.detailTextLabel setText:[NSString stringWithFormat:@"%@ %.02f",p.currency, p.cost]];
cell.imageView.image = [UIImage imageNamed:p.image];
[cell addSubview:lableName];
//[cell release];
//[cell addSubview:counterNumber];
return cell;

推荐答案

之所以发生这种情况,是因为您没有重复使用单元格,因此基本上是一次又一次地添加标签,而不是使用已经存在的标签.

This is happening because you are not reusing cells and hence you are basically adding the label again and again instead of using the already existing one.

只需将以下代码放入if(cell == nil):

Just put the following code inside the if(cell == nil):

static NSString *CellIdentifier = @"OrderProductCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UILabel *lableName;
if(cell==nil){  
    // this is where we should initialize and customize the UI elements,
    // or in this case your label.
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
    lableName=[[UILabel alloc]initWithFrame:CGRectMake(10, 16, 300, 20)];
    lableName.backgroundColor=[UIColor clearColor];
    lableName.font=[UIFont boldSystemFontOfSize:19];
    [lableName setFont:[UIFont fontWithName:@"Arial-Bold" size:12.0]];
    [cell addSubview:lableName];
}
// this is where we should assign the value.
OrderProduct *p = [[order.items allObjects] objectAtIndex:indexPath.row];    
lableName.text = p.name;
/*
assign other values if any
...
*/
return cell;

这样,lableName不会一次又一次地添加到单元格中,因此不会发生此问题.

this way the lableName will not be added to the cell again and again and hence this problem will not occur.

重用单元格属性的最佳方法是初始化和自定义if(cell == nil)内部的所有内容,并仅将元素的值添加到if条件之外.

The best way of reusing a cell properties is initializing and customizing everything inside the if(cell==nil) and only adding the value of the element outside the if condition.

这篇关于向上滚动后,UITableview项变为粗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆