Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UI issue with nil title in UIAlertView iOS 8 beta 5

I have an issue related to UIAlertView while running our app on iOS 8. I am showing an alert with title as nil. It was working fine in iOS 7 but now UI looks odd.

I have attached screenshot here.

enter image description here One solution I found is that when I provide empty string @“” it looks okay. See below screenshot. But I am not sure if the issue I mentioned is bug in beta iOS 8 version or if there is any other better solution. Even with the solution it's not exact as it was in iOS 7.

enter image description here

iOS 7 - showing alert view with title as nil. Screenshot here. enter image description here

like image 621
user1140780 Avatar asked Aug 29 '14 00:08

user1140780


1 Answers

The closest I could get with iOS 8 was by setting the title instead of the message:

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Location field required." message:nil delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];

UIAlertView iOS8 title set

It should be noted, however, that UIAlertView is deprecated in iOS 8 and, if you're going to be using separate code paths for iOS 7 and iOS 8, you should be using UIAlertController instead:

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Location field required."  message:nil preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
    [self dismissViewControllerAnimated:YES completion:nil];
}]];

[self presentViewController:alert animated:YES completion:nil];

I got the same results with both methods.

like image 79
Mike S Avatar answered Sep 19 '22 21:09

Mike S