UIAlertController/UIAlertView scrolling on iOS 8

I’m wondering if anyone knows a good solution to the fact that UIAlertViews and UIAlertControllers won’t scroll on iOS 8? Here is an example:

[[[UIAlertView alloc] initWithTitle:@"Test" message:@"long string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong
string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\n
long string\nlong string\nlong string\nlong string\nlong string\nlong string\n
long string\nlong string\nlong string\nlong string\nlong string\nlong string\n"
delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil] show];

Running that code on iOS 7 and 8 produces the following results. (Changing it to UIAlertController makes no difference).

  • Errors thrown from here are not handled for do { } catch in Swift 2.0
  • UIButton with UITableViewCellSelectionStyleGray Selection Color
  • How to call iCarte SDK methods for scanning RFID
  • For loop and if statement
  • How to create equal spacing between multiple label in ios xcode 6.3 using AutoLayout Constraints
  • NSButton how to color the text
  • iOS 8:
    iOS 8:

    iOS 7:
    iOS 7:

    As you can see it clearly scrolls on iOS 7 but not on iOS 8. Is there some property that I’m missing here or is it just a beta bug?

    5 Solutions Collect From Internet About “UIAlertController/UIAlertView scrolling on iOS 8”

    Although I dunno the right way, I could solve the issue anyway.
    Seems like the view scrolls if you set the frame property (but not CGRectZero).
    It worked fine on iOS 8.0.2.

    NSString* messageString = @"long string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\n";
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Title"
                                                                             message:messageString
                                                                      preferredStyle:UIAlertControllerStyleAlert];
    
    alertController.view.frame = [[UIScreen mainScreen] applicationFrame];
    
    [alertController addAction:[UIAlertAction actionWithTitle:@“OK”
                                                        style:UIAlertActionStyleDefault
                                                      handler:^(UIAlertAction *action){
                                                          [self okButtonTapped];
                                                      }]];
    [self presentViewController:alertController animated:YES completion:nil];
    
    //——
    - (void) okButtonTapped{};
    

    cafedeichi’s solution didn’t work for me, so I ended up using DTAlertView which works both on iOS 8 and iOS 7.

    The problem has been fixed on iOS 8.3
    I’ve been using cafedeichi solution, but if isn’t working on landscape mode for iPhones and iPod touch devices, and if you add a textfield it will crash on iOS 8.3, so I’m using this code right now that fixes the two problems mentioned:

    NSString* messageString = @"long string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\nlong string\n";
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Title"
                                                                             message:messageString
                                                                      preferredStyle:UIAlertControllerStyleAlert];
    
    if ([[[UIDevice currentDevice] systemVersion] floatValue] < 8.3) {
    
        CGFloat screenHeight;
        CGFloat screenWidth;
        if ([[UIApplication sharedApplication] statusBarOrientation] == UIDeviceOrientationPortrait || [[UIApplication sharedApplication] statusBarOrientation] == UIDeviceOrientationPortraitUpsideDown){
            screenHeight = [UIScreen mainScreen].applicationFrame.size.height;
            screenWidth = [UIScreen mainScreen].applicationFrame.size.width;
        } else{
            screenHeight = [UIScreen mainScreen].applicationFrame.size.width;
            screenWidth = [UIScreen mainScreen].applicationFrame.size.height;
        }
        CGRect alertFrame = CGRectMake([UIScreen mainScreen].applicationFrame.origin.x, [UIScreen mainScreen].applicationFrame.origin.y, screenWidth, screenHeight);
                alertController.view.frame = alertFrame;
    
    }
    
    [alertController addAction:[UIAlertAction actionWithTitle:@“OK”
                                                        style:UIAlertActionStyleDefault
                                                      handler:^(UIAlertAction *action){
                                                          [self okButtonTapped];
                                                      }]];
    [self presentViewController:alertController animated:YES completion:nil];
    
    //——
    - (void) okButtonTapped{};
    

    Use this :

    NSString *message = @"YOUR LONG MESSAGE" ;    
    NSInteger lines = [[message componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]] count];
    
        UITextView *txtView = nil ;
        if (lines > MAX_LINES_TO_SHOW)
        {
            txtView = [[UITextView alloc] init];
            [txtView setBackgroundColor:[UIColor clearColor]];
            [txtView setTextAlignment:NSTextAlignmentCenter] ;
            [txtView setEditable:NO];
            [txtView setText:message];
        }
    
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] ;
        [alert setValue:txtView forKey:@"accessoryView"];
        [alert setTag:tag] ;
        [alert show] ;
    

    Any UIAlertView instances have to first be changed to UIAlertController instances. (They can be used pretty much the same way.) After changing it to a UIAlertController, set the frame property to the application main screen. (setting view.frame of UIAlertView doesn’t help) Evidently, they are depreciating UIAlertViews in IOS8, although it isn’t as clear as it should be.