用了辣么久的tableview ,居然是错的。。好糗 ╮(╯_╰)╭ 还是记下来好了免得出现不经意地记忆bug.~
#import "oneCell.h"
@implementation oneCell
static int i = 0;
- (void)awakeFromNib {
// Initialization code
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.contentView.backgroundColor = [UIColor purpleColor];
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 200, 20)];
label.textColor = [UIColor blackColor];
label.text = @"label";
[self.contentView addSubview:label];
i++;
NSLog(@"%d",i);
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
}
@end
[_table registerClass:[oneCell class] forCellReuseIdentifier:@"one"];
------------------------ (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *one = @"one";
static NSString *two = @"two";
if(indexPath.row%2==0){
oneCell *cell;
cell = [tableView dequeueReusableCellWithIdentifier:one forIndexPath:indexPath];
return cell;
}
else{
TwoCell *cell = [tableView dequeueReusableCellWithIdentifier:two forIndexPath:indexPath];
return cell;
}
}