刚才的UITableViewCell的问题重新描述一下

wmmj23 发布于 2013年09月12日
无人欣赏。

在 storyboard 里设置了 UITableViewCell Identifier "firstCell" 和 class "FirstTableViewCell".
UIViewController中:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   static NSString *CellIdentifier = @"firstCell";
   FirstTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier ];
   NSLog(@"%@",cell);
   if (cell == nil)
   {
       cell = (FirstTableViewCell *)[[FirstTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ;
   }
    return cell;
}

会输出:

2013-09-12 22:26:08.126 Info[5166:c07] <FirstTableViewCell: 0x7579180; baseClass = UITableViewCell; frame = (0 0; 320 44); layer = <CALayer: 0x7579300>>   

2013-09-12 22:26:08.342 Info[5166:c07] <FirstTableViewCell: 0x7579180; baseClass = UITableViewCell; frame = (0 0; 320 44); hidden = YES; autoresize = W; layer = <CALayer: 0x7579300>>

2013-09-12 22:26:08.344 Info[5166:c07] <FirstTableViewCell: 0x819b210; baseClass = UITableViewCell; frame = (0 0; 320 44); layer = <CALayer: 0x8179ad0>>

2013-09-12 22:26:08.346 Info[5166:c07] <FirstTableViewCell: 0x8378360; baseClass = UITableViewCell; frame = (0 0; 320 44); layer = <CALayer: 0x8375df0>>

可以看到第二行和第一行的内存地址是一个,但是第二行出现的慢,第二行以后地址都在变,响应速度也快了这是出于什么原因呢?代码功能就是在不同的行设置不同的label 和画个不同的uiview

Cell代码: @implementation FirstTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
  self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
    // Initialization code
}
return self;
}
-(void)setCa:(Categories *)ca{

UILabel *nameLabelView = (UILabel *)[self.contentView viewWithTag:1];
nameLabelView.text=ca.name;

UILabel *detailLabelView = (UILabel *)[self.contentView viewWithTag:2];
detailLabelView.text=[ca.count stringValue];

UIView *left =(UIView *) [self.contentView viewWithTag:3];
UIView *fill;



int tmp = [ca.id intValue];

switch (tmp) {
    case 1:
        fill = [[CreditView alloc]initWithFrame:CGRectMake(0, 0, 27, 27)];         

        break;
    case 2:
        fill = [[BankView alloc]initWithFrame:CGRectMake(0, 0, 27, 27)];
        break;
    case 3:
        fill = [[QuestionView alloc]initWithFrame:CGRectMake(0, 0, 27, 27)];
        break;
    case 4:
        fill = [[SoftwareView alloc]initWithFrame:CGRectMake(0, 0, 27, 27)];
        break;
    case 5:
        fill = [[NoteView alloc]initWithFrame:CGRectMake(0, 0, 27, 27)];
        break;

    default:
        break;
}

[left addSubview:fill];
[left setNeedsDisplay];
[nameLabelView setNeedsDisplay];
[detailLabelView setNeedsDisplay];

}

-(void)setcaNil:(int) sum {


UILabel *nameLabelView = (UILabel *)[self.contentView viewWithTag:1];
nameLabelView.text=@"All";

UILabel *detailLabelView = (UILabel *)[self.contentView viewWithTag:2];
detailLabelView.text=[[NSNumber numberWithInt:sum] stringValue];

UIView  *f =(UIView *) [self.contentView viewWithTag:3];

AllView * ui = [[AllView alloc]initWithFrame:CGRectMake(0, 0, 27, 27)];
[f addSubview:ui];


[f setNeedsDisplay];
[nameLabelView setNeedsDisplay];
[detailLabelView setNeedsDisplay];
}
共3条回复
tinyfool 回复于 2013年09月13日

你代码里面为什么有那么多setNeedsDisplay?

allo_shuang 回复于 2013年09月13日

感觉left和f会显示重叠的东西...

wmmj23 回复于 2013年09月13日

1楼 @tinyfool 即使注掉了也没有太大印象

2楼 @allo_shuang 只有第一条是用到f的,后面的都是用left这个方法

而且这种慢的情况只会出现在程序第一次运行的时候,之后只要在内存中就不会慢了

登录 或者 注册
相关帖子