whyoz whyoz - 1 month ago 12
iOS Question

iOS 10: UIAlertController only showing one action

I have a UIAlertController:

UIAlertController *actionSheet = [UIAlertController
alertControllerWithTitle:@"Options"
message:@""
preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *start = [UIAlertAction
actionWithTitle:@"Start"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{

[self DisplayAlert:@"" textval:@"You are about to start. Would you like to continue?"];
[actionSheet dismissViewControllerAnimated:YES completion:nil];
}];
UIAlertAction *idle = [UIAlertAction
actionWithTitle:@"Idle"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{

[self DisplayAlert:@"" textval:@"You are about to idle. Would you like to continue?"];
[actionSheet dismissViewControllerAnimated:YES completion:nil];
}];
UIAlertAction *stop = [UIAlertAction
actionWithTitle:@"Stop"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{

[self DisplayAlert:@"" textval:@"You are about to stop. Would you like to continue?"];
[actionSheet dismissViewControllerAnimated:YES completion:nil];
}];
UIAlertAction *enable = [UIAlertAction
actionWithTitle:@"Enable"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{

[self DisplayAlert:@"" textval:@"You are about to enable. Would you like to continue?"];
[actionSheet dismissViewControllerAnimated:YES completion:nil];
}];

UIAlertAction *disable = [UIAlertAction
actionWithTitle:@"Disable"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{

[self DisplayAlert:@"" textval:@"You are about to disable. Would you like to continue?"];
[actionSheet dismissViewControllerAnimated:YES completion:nil];
}];

UIAlertAction *clear = [UIAlertAction
actionWithTitle:@"Clear"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{

[self DisplayAlert:@"" textval:@"You are about to clear. Would you like to continue?"];
[actionSheet dismissViewControllerAnimated:YES completion:nil];
}];
UIAlertAction *cancel = [UIAlertAction
actionWithTitle:@"Cancel"
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction * action)
{
[actionSheet dismissViewControllerAnimated:YES completion:nil];
}];


[actionSheet addAction:start];
[actionSheet addAction:idle];
[actionSheet addAction:stop];
[actionSheet addAction:enable];
[actionSheet addAction:disable];
[actionSheet addAction:clear];
[actionSheet addAction:cancel];
[actionSheet setModalPresentationStyle:UIModalPresentationPopover];
[actionSheet.view setTintColor:[UIColor blackColor]];
UIPopoverPresentationController *popPresenter = [actionSheet popoverPresentationController];
popPresenter.barButtonItem = wellControlItem;
[appDelegate.splitViewController presentViewController:actionSheet animated:YES completion:nil];


enter image description here

Why is only one of these actions showing when the menu is displayed on an iPad? I tested this on a 10.1 iPad sim and device (not working on either), as well as a 10.1 iPhone 7 sim and device (working on all iPhones).

This has been working since I fixed it after iOS 8 was released (setTintColor was added). Debugging this is showing "7 actions" added, so I'm not sure where to go from here for the UIAlertControllerStyleActionSheet, which is the desired display option. UIAlertControllerStyleAlert shows all 7 but I like the old UIAlertControllerStyleActionSheet look.

Answer

Under iOS 10, showing a UIAlertController with a style of "ActionSheet" doesn't work properly if you attempt to set the alert controller view's tintColor. I ran into this issue when updating my app for iOS 10. I filed a bug report with Apple.

So your primary issue will be solved by not calling:

[actionSheet.view setTintColor:[UIColor blackColor]];

under iOS 10.

Unrelated to this problem, your code is mistakenly attempting to dismiss the alert controller from inside the various alert actions. Do not do this. The alert will be dismissed automatically. You need to remove all of your calls to:

[actionSheet dismissViewControllerAnimated:YES completion:nil];