UITableView backgroundColor zawsze szary na iPadzie

Po ustawieniu backgroundColor dla mojego UITableView działa dobrze na iPhonie (urządzenie i symulator), ale nie na symulatorze iPada. Zamiast tego otrzymuję jasnoszare tło dla dowolnego koloru, który ustawiłem, w tym groupTableViewBackgroundColor.

Kroki do odtworzenia:

  1. Utwórz nowy projekt oparty na nawigacji.
  2. Otwórz RootViewController.xib i ustaw styl widoku tabeli na "zgrupowany".
  3. Dodaj ten responder do RootViewController:

    - (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor blackColor];
    }
  4. Wybierz Simulator SDK 3.2, build i uciekaj.
  5. otrzymasz czarne tło(urządzenie i symulator).
  6. Wybierz swój cel w drzewie projektu.
  7. Kliknij Na Project: Upgrade Current Target dla iPada.
  8. budować i biegać.
  9. otrzymasz jasnoszare tło.
  10. odwróć styl widoku tabeli na zwykły, a otrzymasz czarne tło.

Dzięki za pomoc!

Author: jszumski, 2010-04-22

8 answers

Spróbuj tego.

[myTableView setBackgroundView:nil];
[myTableView setBackgroundView:[[[UIView alloc] init] autorelease]];
 245
Author: drawnonward,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-01-07 19:58:31

Wielkie dzięki za takie rozwiązanie. Zastosowałem to na właściwości UITableView z IBOutlet w UIViewController i działa dobrze jak:

[panelTable setBackgroundView:nil];
[panelTable setBackgroundView:[[[UIView alloc] init] autorelease]];
[panelTable setBackgroundColor:UIColor.clearColor]; // Make the table view transparent
 30
Author: Alexander,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-06-15 15:13:17

Na iPadzie Właściwość backgroundView wydaje się być używana do tworzenia szarego koloru tła dla tabel zgrupowanych. Aby zmienić kolor tła tabel zgrupowanych na iPadzie, należy nil wyjąć Właściwość backgroundView, a następnie ustawić backgroundColor na żądanym widoku tabeli.

- (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];
}
 6
Author: Philipp Frischmuth,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-04-20 10:37:56

Myślę, że warto zauważyć, że od Xcode 6.1 i iOS 8.1, specjalnie dla iPada (jeśli chcesz ustawić tło komórki, jak również) wydaje się, że należy ustawić tło tabeli i tło komórki.

Na przykład na storyboardzie iPhone ' a możesz ustawić komórkę na czysty kolor, a następnie programowo ustawić obraz tła tabeli dla przezroczystej tabeli z obrazem tła. Jednak jeśli miałbyś zobaczyć tę samą konfigurację na iPadzie, komórki nie byłyby jasne. Komórki będą musiały być Ustaw, aby wyczyścić programowo dla iPada.

 2
Author: WiseGuy,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-12-08 19:04:18

Próbowałem ustawić backgroundColor i widok dla tabeli, nie miałem szczęścia (Xcode 5 iOS7. 1 ipad simulator), wyglądał OK dla iPhone, ale jasnoszary kolor tła na iPadzie...

Praca z backgroundColor dla samej komórki naprawiła to dla mnie na 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;

}

 1
Author: cube108,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-04-02 01:59:27

Jeśli Twoja aplikacja jest skierowana zarówno na iPhone ' a, jak i iPada, możesz to zrobić w następujący sposób:

[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

Zauważ, że TableView alloc nie ma autorelease dla ARC.

 0
Author: gmogames,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-06-14 14:33:58

Jeśli dodajesz UIViewController do innego UIViewController, musisz również ustawić tło widoku na clearColor oprócz UITableView, w przeciwnym razie otrzymasz białe tło zamiast jasnoszarego.

if ([myViewController.myTableView respondsToSelector:@selector(setBackgroundView:)]) {
    [myViewController.myTableView setBackgroundView:nil];
}
myViewController.myTableView.backgroundColor = [UIColor clearColor];
myViewController.view.backgroundColor = [UIColor clearColor];
 0
Author: irmu,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-07-12 07:29:15
  • Symulacja iPada 2
  • Uruchamianie iOS od 7.1 do 8.3
  • zbudowany z XCode 6.3

Żadne z powyższych nie działało dla mojego UIViewController->UITableView określonego za pomocą pojedynczego XIB. To, co zadziałało, to przeniesienie całej konfiguracji do storyboardu i ustawienie koloru tła za pomocą Inspektora IB.

 0
Author: QED,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-04-16 19:06:31