iPhone 12上的UIAlertController标题和消息未显示

8

我使用UIAlertControllerStyleActionSheet样式展示了UIAlertController。使用XCode 13在iPhone 12上构建时,UIAlertController的标题和消息无法正常工作,但在其他设备上可以正常工作。同样的代码先前在iPhone 12上也能正常工作。

-(void)alertSheetUI{
dispatch_async(dispatch_get_main_queue(), ^{
    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"Static Title" message:@"Static Message" preferredStyle:UIAlertControllerStyleActionSheet];
    
    [actionSheet addAction:[UIAlertAction actionWithTitle:@"Data 1" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
    }]];
    [actionSheet addAction:[UIAlertAction actionWithTitle:@"Data 2" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
    }]];
    [actionSheet addAction:[UIAlertAction actionWithTitle:@"Data 3" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
    }]];
    
    [actionSheet addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
        
        [[[UIApplication sharedApplication] delegate].window.rootViewController dismissViewControllerAnimated:YES completion:^{
        }];
    }]];
    [[[UIApplication sharedApplication] delegate].window.rootViewController presentViewController:actionSheet animated:NO completion:nil];
});}

iPhone 12

图片描述

iPhone SE 图片描述

视图层次结构显示标题和消息为白色。因此,只有标题和消息不可见。我尝试使用下面的代码将标题和消息设置为绿色,并使用属性文本。但在其他设备上,标题和消息颜色未更新。其他设备显示为灰色。

更新后的代码

-(void)alertSheetUI{

dispatch_async(dispatch_get_main_queue(), ^{

        NSString * string = @"Static Title";
        NSMutableAttributedString * attrString = [[NSMutableAttributedString alloc] initWithString:@"Static Title"];
        [attrString addAttribute:NSForegroundColorAttributeName
                                 value:[UIColor greenColor] range:NSMakeRange(0, [string length])];
        UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"Static Title" message:@"Static Message" preferredStyle:UIAlertControllerStyleActionSheet];
        [actionSheet setValue:attrString forKey:@"attributedTitle"];
        [actionSheet setValue:attrString forKey:@"attributedMessage"];

        [actionSheet addAction:[UIAlertAction actionWithTitle:@"Data 1" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        }]];
        [actionSheet addAction:[UIAlertAction actionWithTitle:@"Data 2" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        }]];
        [actionSheet addAction:[UIAlertAction actionWithTitle:@"Data 3" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        }]];

        [actionSheet addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {

            [[[UIApplication sharedApplication] delegate].window.rootViewController dismissViewControllerAnimated:YES completion:^{
            }];
        }]];
        [[[UIApplication sharedApplication] delegate].window.rootViewController presentViewController:actionSheet animated:NO completion:nil];
    });}

enter image description here


1
正在运行的设备系统版本是什么?图片显示你是否自定义了UIAlertController的外观? - childrenOurFuture
@Anbu.Karthik 在 iPhone 12 模拟器上运行良好。 - Siva
2
调色板颜色/UI外观的自定义已完成?文本在白色背景上似乎是“白色”的,因此看不见。如果您检查(例如使用调试视图层次结构),则可以看到文本存在,对吧? - Larme
所以文本已经正确设置和呈现。问题在于它的颜色。如先前所述,您是否更改了UIViewController的tintColor? - Larme
@Ranjani - 当您在视图加载或任何按钮操作中调用此 alertSheetUI - Anbu.Karthik
显示剩余7条评论
1个回答

0
您的代码确实请求uiapplication显示警报。您可以尝试使用以下内容:
 dispatch_async(dispatch_get_main_queue(), ^{
    [self presentViewController:actionShert animated:YES completion:nil];
});

主要的异步队列仅在显示或呈现警报时才需要。

库内创建了一个屏幕。我没有自身对象。所以你的答案在我的情况下不起作用。 - Siva

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接