现在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)里面的东西。