3 つのボタンを持つカスタム tableviewcell を使用しています。
カスタムセルで、layoutSubviews メソッド内のボタンのフレームを設定します。
-(void)layoutSubviews
{
[super layoutSubviews];
CGRect frame;
if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
{
frame = CGRectMake(310, 7, 55, 35);
_prod.frame = frame;
frame = CGRectMake(365, 7, 55, 35);
_leva.frame = frame;
frame = CGRectMake(220, 4, 65, 65);
_imageButton.frame = frame;
}
else{
frame = CGRectMake(150, 7, 55, 35);
_prod.frame = frame;
frame = CGRectMake(205, 7, 55, 35);
_leva.frame = frame;
frame = CGRectMake(120, 4, 65, 65);
_imageButton.frame = frame;
}
}
問題は、ユーザーが方向を横に変更した後にテーブルビューをスクロールすると、すべてのボタンが古い縦位置に戻ることです。そして、セルを初期化する方法は次のとおりです。
LojaCell *cell = (LojaCell *) [tableView dequeueReusableCellWithIdentifier: @"LojaCell"];
if(cell == nil) cell = [[LojaCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"LojaCell"];