سؤال

عندما قمت بتعيين backgroundColor لاجلي UITableView إنه يعمل بشكل جيد على iPhone (الجهاز ومحاكاة) ولكن ليس على جهاز محاكاة iPad. بدلاً من ذلك أحصل على خلفية رمادية فاتحة لأي لون قمت بتعيينه بما في ذلك groupTableViewBackgroundColor.

خطوات للتكاثر:

  1. إنشاء مشروع جديد قائم على الملاحة.
  2. Open 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 مع Iboutlet في UiviewController وتعمل بشكل جيد مثل:

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

على iPad backgroundView يبدو أن الخاصية تستخدم لإنشاء لون الخلفية الرمادية للجداول المجمعة. لذلك لتغيير لون الخلفية للجداول المجمعة على iPad يجب على المرء nil خارج ال backgroundView الممتلكات ثم اضبط 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 Simulator) ، بدا جيدًا على iPhone ، ولكن لون الخلفية الرمادي الفاتح على iPad ...

العمل مع خلفية اللون للخلية نفسها إصلاح هذا بالنسبة لي على 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 illoC ليس لديه Autorelease لـ ARC.

إذا كنت تقوم بإضافة uiviewController إلى uiviewController آخر ، فأنت بحاجة أيضًا إلى تعيين خلفية عرضك على ClearColor بالإضافة إلى UitableView وإلا ستحصل على خلفية بيضاء بدلاً من الرمادي الفاتح.

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

لم يعمل أي مما سبق في UiviewController-> UableView المحدد باستخدام XIB واحد. ما الذي عمل هو نقل الإعداد بالكامل إلى لوحة العمل ، ووضع لون الخلفية باستخدام مفتش IB.

لقد حصلت أيضًا على هذا النوع من المشكلات. ال UITableView سيكون لون الخلفية دائمًا groupTableViewBackgroundColor لا يهم ما حددته.

الأعراض مثل هذه المشكلة - تقوم UitableView بإعادة ضبط لون الخلفية قبل ظهور العرض

بعد ضبط لون الخلفية في init وظيفة ، هذا صحيح. في viewDidLoad و viewWillAppear المرحلة ، هذا صحيح. ومع ذلك، في 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