自 2011 年以来,我一直在为我的医疗应用程序使用 Objective-C 代码,它基本上有 5 个带有关联 UITableViews 的选项卡,其中 3 个使用自定义单元格。最初使用暗模式时,我发现自定义单元格不会自动更改为暗模式。相反,我需要实现下面的代码来测试暗模式并相应地更改单元格文本和背景。
问题是第一个选项卡中的空单元格不会发生暗模式更改,填充单元格的上方或下方;它们仍然是空白的白色。但是,与第二个 2 个选项卡关联的 UITableViews 中类似的空单元格在暗模式下的行为与预期相同。
下面的示例图像显示了第一个和第三个选项卡显示的单元格。我现在想知道操作系统中是否存在错误,或者我是否没有实施适当的更改,以解释为什么暗模式仅在第一个选项卡中无法正常工作。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CustomCellIdentifier = @"CustomCellIdentifier ";
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier: CustomCellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
for (id oneObject in nib)
if ([oneObject isKindOfClass:[CustomCell class]])
cell = (CustomCell *)oneObject;
}
NSDictionary *dictionary = [self.tableDataSource objectAtIndex:indexPath.row];
cell.calculationLabel.text = [dictionary objectForKey:@"Title"];
[cell.calculationLabel setLineBreakMode:NSLineBreakByWordWrapping];
cell.calculationLabel.numberOfLines = 0;
//Make color changes in cells relevant to Dark mode, if present.
if (self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) { //Dark mode
cell.calculationLabel.textColor = [UIColor whiteColor];
cell.calculationLabel.backgroundColor = [UIColor blackColor];
cell.statusLabel.backgroundColor = [UIColor blackColor];
cell.favoriteStatus.backgroundColor = [UIColor blackColor];
cell.backgroundColor = [UIColor blackColor];
} else { //Light mode
cell.calculationLabel.textColor = [UIColor blackColor];
cell.calculationLabel.backgroundColor = [UIColor whiteColor];
cell.statusLabel.backgroundColor = [UIColor whiteColor];
cell.favoriteStatus.backgroundColor = [UIColor whiteColor];
cell.backgroundColor = [UIColor whiteColor];
}
cell.statusLabel.textColor = [UIColor systemGreenColor];