質問

設定するとき backgroundColor 私のために UITableView iPhone(デバイスとシミュレーター)では正常に動作しますが、iPadシミュレーターではうまく機能しません。代わりに、私が設定したあらゆる色の明るい灰色の背景を取得します groupTableViewBackgroundColor.

再現する手順:

  1. 新しいナビゲーションベースのプロジェクトを作成します。
  2. rootviewcontroller.xibを開き、テーブルビュースタイルを「グループ化」に設定します。
  3. このレスポンダーをrootViewControllerに追加します。

    - (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor blackColor];
    }
  4. Simulator SDK 3.2を選択し、ビルドして実行します。
  5. 黒い背景(デバイスとシミュレーター)が得られます。
  6. プロジェクトツリーでターゲットを選択します。
  7. プロジェクトをクリックします:iPadの現在のターゲットをアップグレードします。
  8. 構築して実行します。
  9. 明るい灰色の背景が得られます。
  10. テーブルビュースタイルをプレーンに戻すと、黒い背景が得られます。

ご協力いただきありがとうございます!

役に立ちましたか?

解決

これらのいずれかを試してください。

[myTableView setBackgroundView:nil];
[myTableView setBackgroundView:[[[UIView alloc] init] autorelease]];

他のヒント

このソリューションをありがとうございました。これをuitableviewプロパティにuiviewcontrollerに入れて適用しましたが、次のように機能します。

[panelTable setBackgroundView:nil];
[panelTable setBackgroundView:[[[UIView alloc] init] autorelease]];
[panelTable setBackgroundColor:UIColor.clearColor]; // Make the table view transparent

iPadで backgroundView プロパティは、グループ化されたテーブルの灰色の背景色を作成するために使用されるようです。したがって、iPadのグループ化されたテーブルの背景色を変更するには、 nilbackgroundView プロパティしてから設定します backgroundColor 目的のテーブルビュー。

- (void)viewDidLoad
{
    [super viewDidLoad];

    // If you need to support iOS < 3.2, check for the availability of the
    // backgroundView property.
    if ([self.tableView respondsToSelector:@selector(setBackgroundView:)]) {
        self.tableView.backgroundView = nil;
    }
    self.tableView.backgroundColor = [UIColor whiteColor];
}

Xcode 6.1およびiOS 8.1の時点で、特にiPad専用に(セルの背景も設定する場合)、テーブルの背景とセルの背景を設定する必要があるようです。

たとえば、iPhoneストーリーボードでは、セルを色に設定して色をクリアし、背景画像を備えた透明なテーブルのテーブルの背景画像をプログラムで設定できます。ただし、iPadでこの同じ構成を表示する場合、セルは明確ではありません。 iPadのプログラム的にクリアするようにセルを設定する必要があります。

バックグラウンドコラーとテーブルのビューを設定しようとしましたが、運がありませんでした(Xcode 5 iOS7.1 iPadシミュレーター)、iPhoneでは問題ありませんでしたが、iPadの明るい灰色の背景色...

Cell自体のBackgroundColorを使用して、iOS 7.1 4/2014でこれを修正しました

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

        static NSString *CellIdentifier = @"ViewSomeTriggerCell";

        // get a cell or a recycled cell
        sictVCViewSomeTriggerCell *cellTrigger = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

        // put a picture and a word in the cell (positions set in .xib)
        NSString * tname = [self.fetchedTriggersArray objectAtIndex:indexPath.row];
        cellTrigger.imageTrigger.image = [UIImage imageNamed:@"icon_appicon.png"];
        cellTrigger.labelName.text = tname;

        // set background color, defeats iPad wierdness
        // http://stackoverflow.com/questions/2688007/uitableview-backgroundcolor-always-gray-on-ipad

        // clearColor is what I wanted, and it worked, also tested with purpleColor
        cellTrigger.backgroundColor =[UIColor clearColor];
        return cellTrigger;

}

アプリケーションがiPhoneとiPadの両方をターゲットにしている場合、次のように行うことができます。

[myTableView setBackgroundColor:[UIColor clearColor]]; // this is for iPhone

if ([[UIDevice currentDevice] userInterfaceIdiom] != UIUserInterfaceIdiomPhone) {
    [myTableView setBackgroundView:nil];
    [myTableView setBackgroundView:[[UIView alloc] init]];
} // this is for iPad only

TableView AllocにはArcのAutoreleaseがないことに注意してください。

別のuiviewcontrollerにuiviewcontrollerを追加している場合は、uitableviewに加えてclearcolorにビューの背景を設定する必要があります。そうでなければ、明るい灰色の代わりに白い背景が得られます。

if ([myViewController.myTableView respondsToSelector:@selector(setBackgroundView:)]) {
    [myViewController.myTableView setBackgroundView:nil];
}
myViewController.myTableView.backgroundColor = [UIColor clearColor];
myViewController.view.backgroundColor = [UIColor clearColor];
  • iPad 2のシミュレーション
  • iOS 7.1から8.3の実行
  • Xcode 6.3から構築されています

上記のいずれも、単一のXIBを使用して指定された私のuiviewcontroller-> uitableViewで機能しませんでした。仕事があったのは、セットアップ全体をストーリーボードに移動し、IBインスペクターを使用して背景色を設定することでした。

この種の問題もあります。 UITableView 背景色は常になります groupTableViewBackgroundColor 何を設定しても。

症状はこの問題のようなものです - uitableviewは、ビューが表示される前に背景色をリセットしています

背景色をに設定した後 init 機能、それは正しいです。の viewDidLoadviewWillAppear ステージ、それは正しいです。しかし、で viewDidAppear, 、背景色はデフォルトの色にリセットされます。

受け入れられた答えは今は機能しません。

[myTableView setBackgroundView:nil];
[myTableView setBackgroundView:[[UIView alloc] init]];

これが私の解決策です。 TableViewの背景色をに設定するだけです viewDidLoad 働き それよりも init また viewWillAppear.

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.backgroundColor = [UIColor clearColor];
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top