UITableViewCell 复用

1从xib中加载cellcode

 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代码加载it

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

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

  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;
            }
     }
相关文章
相关标签/搜索