Search code examples
iosios9uialertcontroller

iOS 9.0 - Remove top bar from UIAlertController action sheet


When creating an action sheet with UIAlertController, I'm seeing a top bar always show. This SO post suggests setting the title to nil - this might work on iOS 8.0, but I'm seeing a top bar on iOS 9.0.

enter image description here


Solution

  • Set message to nil also:

    UIAlertController *actionSheet= [UIAlertController
                                     alertControllerWithTitle:nil
                                     message:nil
                                     preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction *actionSheetButton1 = [UIAlertAction
                                         actionWithTitle:@"Button 1"
                                         style:UIAlertActionStyleDefault
                                         handler:^(UIAlertAction * action)
                                         {
                                             NSLog(@"Button 1 pressed");
                                         }];
    UIAlertAction *actionSheetButton2 = [UIAlertAction
                                         actionWithTitle:@"Button 2"
                                         style:UIAlertActionStyleDefault
                                         handler:^(UIAlertAction * action)
                                         {
                                             NSLog(@"Button 2 pressed");
                                         }];
    UIAlertAction *actionSheetButton3 = [UIAlertAction
                                         actionWithTitle:@"Close Button"
                                         style:UIAlertActionStyleCancel
                                         handler:^(UIAlertAction * action)
                                         {
                                             NSLog(@"Close Button pressed");
                                         }];
    
    [actionSheet addAction:actionSheetButton1];
    [actionSheet addAction:actionSheetButton2];
    [actionSheet addAction:actionSheetButton3];
    [self presentViewController:actionSheet animated:YES completion:nil];
    

    enter image description here