iOS xib文件引入的两种方式

现在xib文件的加载方式有两种:
1 UITableViewCell* cell = [[[NSBundle mainBundle]loadNibNamed:@”ChamberTableViewCell” owner:nil options:nil] firstObject];
2 [self.view registerNib:[UINib nibWithNibName:@”ChamberTableViewCell” bundle:nil] forCellReuseIdentifier:@”ChamberTableViewCell”];

别的代码
static NSString *chamberCell = @”ChamberTableViewCell”;

if (indexPath.section == 0) {

    VoteTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:voteCell];


    if (cell==nil) {
        cell = [[[NSBundle mainBundle]loadNibNamed:@"VoteTableViewCell" owner:nil options:nil] firstObject];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.backgroundColor = [UIColor clearColor];


        UIView *tempView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, voteCellHeight)];
        UIView *colourView = [[UIView alloc]initWithFrame:CGRectMake(15, 0, WIDTH-30, voteCellHeight)];
        colourView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.2];
        tempView.backgroundColor = [UIColor clearColor];
        [tempView addSubview:colourView];
        cell.selectedBackgroundView = tempView;

    }

我发现这两种xib加载的方式不一样,第二种加载后直接放到内存里面,所以下面cell直接不为空,不能加载if(cell == nill)里面的东西,第一种方式加载不直接到内存里面,只有当用到的时候才会加载到内存里面,这样可以加载if(cell == nill)里面的东西。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值