2009-05-16 12 views
5

を回転させたとき、私はそのセル内のテキストをもとに、デリゲートメソッド-tableView:heightForRowAtIndexPath:をオーバーロードして、プログラムでセルの高さを設定する-sizeWithFont:constrainedToSize:を使用しています:リセットカスタムUITableViewCellの高さiPhoneが

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
    switch (indexPath.section) { 
    case(kAboutViewOverviewSection): { 
     switch (indexPath.row) { 
     case(kAboutViewOverviewSectionRow): { 
      NSString *text = NSLocalizedString(@"kAboutViewOverviewSectionFieldText", @""); 
      CGSize s = [text sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:CGSizeMake(280, 500)]; 
      return s.height + 13; 
     } 
     default: { 
      break; 
     } 
     } 
     break; 
    } 
    default: { 
     break; 
    } 
    } 
    return 44.0; 
} 

ときテーブルこれは動作します最初に描画されます。しかし、デバイスの向きをポートレートからランドスケープに変更すると、セルの高さは変化しません。

私はテーブルビューコントローラに-shouldAutorotateToInterfaceOrientation:メソッドをオーバーライドする試み:

- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    [self.tableView reloadData]; 
    return YES; 
} 

これはテーブルデータを再ロードし、(おそらく)テーブルセルビューを再描画しなければなりません。しかし、これは何の効果もありません。

デバイスを回転させたときに、新しい高さのセルを強制的に再描画する方法はありますか?

EDIT:私は効果なしに、次のことを試してみました:ここ

- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    [self.tableView reloadData]; 
} 

アプリケーションが縦向きで次のようになります。ここでは

Portait

は何のアプリケーションです横向きのようです:

Landscape

コンテンツの上端と下端の間に隙間があります。

EDIT 2

CGSize s = [text sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:CGSizeMake([tableView frame].size.width,500)]; 

答えて

6

それは最適ではないですが、最も簡単な解決策は、上-reloadDataを呼び出すことです:テーブルフレームの幅を経由してサイズパラメータを調整するには、

この表示の問題を修正する助け表。

より良い解決策は3.0をターゲット場合-beginUpdates-deleteRowsAtIndexPaths:withRowAnimation:-insertRowsAtIndexPaths:withRowAnimation:、および-endUpdatesまたは単に-reloadSections:withRowAnimation:を呼び出すことであろう。アニメーションが追加されます。

編集:そして、あなたはまた、私は-reloadDataをしようとした適切なtableView:heightForRowAtIndexPath:

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
    CGSize textSize = [[self textForRowAtIndexPath:indexPath] sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:CGSizeMake([tableView frame].size.width - 20, 500)]; 
    return textSize.height + 13.0f; 
} 

textForRowAtIndexPath:は、セルのテキストを返すメソッドです)

+0

が必要になります。 –

+0

-shloadAutorotateToInterfaceOrientation:メソッドで-reloadSections:withRowAnimation:を試しましたが、これはうまくいきません。 –

+0

ビューがサイズ変更された後に呼び出された場合、これらはすべて機能します。つまり、彼らはあなたのdidRotateFromInterfaceOrientation: – rpetrich

関連する問題