UI issue with nil title in UIAlertView iOS 8 beta 5

前端 未结 4 1263
栀梦
栀梦 2021-02-13 10:41

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 ha

4条回答
  •  星月不相逢
    2021-02-13 11:15

    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.

提交回复
热议问题