tableview 复用

来源:互联网 发布:如何快速提升淘宝等级 编辑:程序博客网 时间:2024/06/06 02:34

用了辣么久的tableview ,居然是错的。。好糗 ╮(╯_╰)╭  还是记下来好了免得出现不经意地记忆bug.~


#import "oneCell.h"


@implementation oneCell

static int i = 0;

- (void)awakeFromNib {

    // Initialization code

}


- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{

   self = [superinitWithStyle:style reuseIdentifier:reuseIdentifier];

   if (self) {

        self.contentView.backgroundColor = [UIColorpurpleColor];

        UILabel *label = [[UILabelalloc]initWithFrame:CGRectMake(0, 0, 200, 20)];

        label.textColor  = [UIColorblackColor];

        label.text =@"label";

        [self.contentViewaddSubview:label];

       i++;

       NSLog(@"%d",i);

    }

    return self;

}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {

    [supersetSelected:selected animated:animated];

}


@end

-----------------------

[_table registerClass:[oneCellclass] 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:oneforIndexPath:indexPath];

       return cell;

    }

   else{

        TwoCell *cell = [tableViewdequeueReusableCellWithIdentifier:two forIndexPath:indexPath];

       return cell;

    }

    

}


0 0
原创粉丝点击