私の縦向きのテーブルビューセルは、自動サイズ変更マスクを使用しても横向きではうまく機能しないため、新しいxibファイルで再配置しました。
この新しい状況を実装する最善の方法は何ですか? 向きをチェックする一連の if ステートメントを使用して動作させましたが、それはあまりエレガントではないようです。より良い方法はありますか?
私の縦向きのテーブルビューセルは、自動サイズ変更マスクを使用しても横向きではうまく機能しないため、新しいxibファイルで再配置しました。
この新しい状況を実装する最善の方法は何ですか? 向きをチェックする一連の if ステートメントを使用して動作させましたが、それはあまりエレガントではないようです。より良い方法はありますか?
縦向きと横向きの 2 つの UITableViewCell nib ファイルを作成します。2 つの NIB が継承し、カスタマイズされたセルで以下を実装する基本クラスとして UITableViewCell を持つ 1 つのカスタム クラス (CustomCell.h と CustomCell.m ) を作成します。
-(void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
 if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
            [[NSBundle mainBundle] loadNibNamed:@"customCell-Landscape" owner:self options:nil];
        }else
 {
            [[NSBundle mainBundle] loadNibNamed:@"customCell-Portrait" owner:self options:nil];
}
[tableView reloadData];
}
そして、テーブルビューデータソースで
..
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @" identifier";
    CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (!cell) {
        if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) {
            [[NSBundle mainBundle] loadNibNamed:@"customCell-Landscape" owner:self options:nil];
        }else {
            [[NSBundle mainBundle] loadNibNamed:@"customCell-Portrait" owner:self options:nil];
        }
    }