Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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).

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?

like image 703
Rick Avatar asked Jul 10 '14 08:07

Rick


3 Answers

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{};
like image 90
cafedeichi Avatar answered Nov 08 '22 00:11

cafedeichi


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

like image 3
kernix Avatar answered Nov 08 '22 02:11

kernix


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{};
like image 3
jcesarmobile Avatar answered Nov 08 '22 00:11

jcesarmobile