首页 > 其他 > 详细

UITableViewCell 复用

时间:2015-05-08 15:14:27      阅读:251      评论:0      收藏:0      [点我收藏+]

1从xib中加载cell

 static NSString *Identifier = @"CellID";
    if(!nib){
        nib = [UINib nibWithNibName:@"NewsCell" bundle:nil];
        [tableView registerNib:nib forCellReuseIdentifier:Identifier];
    }
    
    NewsCell *cell = [tableView dequeueReusableCellWithIdentifier:Identifier];
    //在cell xib 要设置Identifier

2代码加载

cell = [[NewsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Identifier];

3从xib加载cell(每次都重新加载nib)

  NSArray *objects = [[NSBundle mainBundle] loadNibNamed:@"NewsCell" owner:self options:nil] ;        cell = [objects lastObject];
           NSLog(@"%ld",objects.count);
                  for(NSObject *o in objects){
          if([o isKindOfClass:[NewsCell class]]){
               cell = (NewsCell *)o;
               break;
            }
     }


UITableViewCell 复用

原文:http://my.oschina.net/u/1781028/blog/412257

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!