UITableViewCell 复用

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 复用)