我正在设置一个UIImage,通过UIImageView作为我的子类UITableViewCell的背景视图,如下所示:
-(void)awakeFromNib {
UIImage *backImg = [[UIImage imageNamed:@"CellBackground"]
resizableImageWithCapInsets:UIEdgeInsetsMake(16, 132, 16, 16)];
UIImageView *imv = [[UIImageView alloc] initWithImage:backImg];
self.backgroundView = imv;
}
这非常有效,每个单元格的高度不同(通过heightForRowAtIndexPath公开,它计算UILabel的高度,其中包含文本),背景图像调整大小,因为我想要单元格 .
但是,当我旋转设备时,视图会在旋转中间挂起,需要5-10秒才能在横向中重绘,或者在没有错误的情况下崩溃 . 如果我从backgroundView中删除此imageview,则旋转效果非常好 . 模拟器和设备 .
[编辑]或者,我添加了imageview作为cell.contentView的子视图 - 性能更好,但仍然滞后 .
UIImage *backImg = [[UIImage imageNamed:@"CellBackground"]
resizableImageWithCapInsets:UIEdgeInsetsMake(16, 132, 16, 16)];
UIImageView *imv = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
imv.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
imv.image = backImg;
[self.contentView addSubview:imv];
另外,如上所述,我的UITableViewCell是一个子类 . 上面的代码在awakeFromNib中,我正在加载我的UITableViewCell,如下所示:
// within initWithNibName: of UIViewcontroller:
cellLoader = [UINib nibWithNibName:@"MasterTableViewCell" bundle:[NSBundle mainBundle]];
// and UITableView method:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
MasterTableViewCell *cell = (MasterTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"MasterTableViewCell"];
if (cell == nil) {
NSArray *topLevelItems = [cellLoader instantiateWithOwner:self options:nil];
cell = [topLevelItems objectAtIndex:0];
}
return cell;
}
难道我做错了什么?任何提示?
1 回答
你每次画一个细胞时都在叫这个吗?这真的会伤害你的表现 . 我建议只在绘制新单元格时才这样做 . 看起来就像