次のように、サブクラス化された UITableViewCell の背景ビューとして UIImageView を介して UIImage を設定しています。
-(void)awakeFromNib {
UIImage *backImg = [[UIImage imageNamed:@"CellBackground"]
resizableImageWithCapInsets:UIEdgeInsetsMake(16, 132, 16, 16)];
UIImageView *imv = [[UIImageView alloc] initWithImage:backImg];
self.backgroundView = imv;
}
これはうまく機能し、各セルの高さが異なり (テキストを含む UILabel の高さを計算する heightForRowAtIndexPath を介して公開されます)、セルのサイズに合わせて背景画像のサイズが変更されます。
ただし、デバイスを回転させると、ビューが回転中にハングし、横向きに再描画するのに 5 ~ 10 秒かかるか、エラーなしでクラッシュします。このイメージビューを backgroundView から削除すると、回転がうまく機能します。シミュレーターとデバイスの両方。
[編集] または、cell.contentView のサブビューとして imageview を追加しました - パフォーマンスは向上しましたが、それでも遅延がありました。
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;
}
私は何か間違ったことをしていますか?ヒントはありますか?