xib作为cell的两种初始化方法

方法一:

第一步:
[self.collectionView registerNib:[UINib nibWithNibName:@"xibNamel" bundle:nil] forCellWithReuseIdentifier:@"myCell”];
第二步:
Mycell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"myCell" forIndexPath:indexPath];


方法二:

    Mycell *cell = (Mycell *)[tableView dequeueReusableCellWithIdentifier:mycell];
    if (cell == nil) {
        cell= (mycell *)[[[NSBundle  mainBundle]  loadNibNamed:@"xibName" owner:self options:nil]  lastObject];
    }


前提:xib要先设置identify !!!

猜你喜欢

转载自blog.csdn.net/frankkay/article/details/50488736