4

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"];
4

1 に答える 1

0

テーブルビューがセルをリロードまたは再作成した場合に正しい場所にロードされるように、方向に依存する同じコードを cellForRowAtIndexPath: に追加する必要がある場合があります。パフォーマンスのために画面外のセルを削除する dequeueReusableCells を使用しているため、スクロール時の動作を説明できる可能性があります。

于 2013-03-27T16:04:22.717 に答える