在情节提要中,我设置了 tableviewcell 标识符“firstCell”和类“FirstTableViewCell”。
在 UIView 控制器中:
- (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 20:30:10.378 InfoDrop[4120:c07] FirstTableViewCell: 0x75624b0; baseClass = UITableViewCell; frame = (0 0; 320 44); layer = CALayer : 0x7562610
2013-09-12 20:30:10.584 InfoDrop[4120:c07] FirstTableViewCell: 0x75624b0; baseClass = UITableViewCell; frame = (0 0; 320 44); hidden = YES; autoresize = W; layer = CALayer: 0x7562610
2013-09-12 20:30:10.586 InfoDrop[4120:c07] <FirstTableViewCell: 0x8181a40; baseClass = UITableViewCell; frame = (0 0; 320 44); layer = <CALayer: 0x81a46e0>>
2013-09-12 21:18:08.042 InfoDrop[4415:c07] <FirstTableViewCell: 0x83993e0; baseClass = UITableViewCell; frame = (0 0; 320 44); layer = <CALayer: 0x8398c90>>
为什么不一样?而且你可以看到第二个单元格和第一个单元格之间的时间大于第三个单元格和第二次之间的时间,为什么?谢谢。
@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];
}