8

I displayed UIAlertController with UIAlertControllerStyleActionSheet style. When building with XCode 13 UIAlertController title and message not working on iPhone 12. It's working on other devices. Same code previously working on 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

enter image description here

iPhone SE enter image description here

View hierarchy shows title and message as white color. So only the title and message are not visible. I try to set the title and message as green Using attributed text using the below code. But the title and message color are not updated on other devices also. Other devices displayed as grey.

Updated Code

-(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

Siva
  • 700
  • 6
  • 25
  • try with simulator once – Anbu.Karthik Dec 29 '21 at 06:36
  • 1
    what's the system version of the running device? the pic seems that you have customize the appearance of the UIAlertController? – childrenOurFuture Dec 29 '21 at 09:18
  • @Anbu.Karthik working fine on iPhone 12 simulator – Siva Dec 29 '21 at 09:30
  • @childrenOurFuture Device version is iOS 15. I do not customize UIAlertController UI. It looks like this is only on iPhone 12 using mentioned code. iPhone SE Screen shoot added for reference. – Siva Dec 29 '21 at 09:33
  • 2
    Tint color/UIAppearance customization done? The text seems "white" on white background, so invisible. If you check (with debug view hierarchy for instance), the text is present, right? – Larme Dec 29 '21 at 10:19
  • @Larme I tried to set attributed text with a different color at that time also the title is not displaying. I don’t have a testing device iPhone 12 so unable to check view hierarchy – Siva Dec 29 '21 at 10:40
  • @Anbu.Karthik previously I am checking Sample app code that working fine in the simulator. Our project code creates issues on the simulator also. Question updated – Siva Jan 06 '22 at 10:54
  • @Larme view hierarchy updated – Siva Jan 06 '22 at 10:55
  • So the text is correctly set and present. The issue is its color. As said previously, did you changed tintColor for your UIViewController? – Larme Jan 06 '22 at 11:17
  • @Larme ViewController tint color not changed – Siva Jan 06 '22 at 11:56
  • @Ranjani - when you called this `alertSheetUI` on viewload or any button action – Anbu.Karthik Jan 07 '22 at 02:28
  • @Anbu.Karthik called in button action – Siva Jan 07 '22 at 11:31

1 Answers1

0

Your code does ask the uiapplication to display the alert . You may try to use :

 dispatch_async(dispatch_get_main_queue(), ^{
    [self presentViewController:actionShert animated:YES completion:nil];
});

The main async queue is only needed when showing or presenting the alert.

christophercotton
  • 5,829
  • 2
  • 34
  • 49
Ptit Xav
  • 3,006
  • 2
  • 6
  • 15
  • screen created inside the library. I don't have a self-object. So your answer not working on my scenario – Siva Jan 06 '22 at 10:57