iOS 10: UIAlertController 只显示一个动作
iOS 10: UIAlertController only showing one action
我有一个 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];
为什么在 iPad 上显示菜单时只显示其中一个操作?我在 10.1 iPad SIM 卡和设备(两者都不工作)以及 10.1 iPhone 7 SIM 卡和设备(在所有 iPhones 上工作)上进行了测试。
自从我在 iOS 8 发布(添加了 setTintColor)后修复它以来,它一直有效。调试它显示添加了“7 个动作”,所以我不确定从这里到哪里去获取 UIAlertControllerStyleActionSheet,这是所需的显示选项。 UIAlertControllerStyleAlert 显示所有 7 个,但我喜欢旧的 UIAlertControllerStyleActionSheet 外观。
在 iOS 10 下,如果您尝试设置警报控制器视图的 tintColor
,则显示样式为 "ActionSheet" 的 UIAlertController
无法正常工作。我 运行 在为 iOS 10 更新我的应用程序时遇到了这个问题。我向 Apple 提交了错误报告。
所以您的主要问题将通过不调用来解决:
[actionSheet.view setTintColor:[UIColor blackColor]];
下 iOS 10.
与此问题无关,您的代码错误地试图从各种警报操作中关闭警报控制器。不要这样做。警报将自动解除。您需要删除对以下内容的所有调用:
[actionSheet dismissViewControllerAnimated:YES completion:nil];
我有一个 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];
为什么在 iPad 上显示菜单时只显示其中一个操作?我在 10.1 iPad SIM 卡和设备(两者都不工作)以及 10.1 iPhone 7 SIM 卡和设备(在所有 iPhones 上工作)上进行了测试。
自从我在 iOS 8 发布(添加了 setTintColor)后修复它以来,它一直有效。调试它显示添加了“7 个动作”,所以我不确定从这里到哪里去获取 UIAlertControllerStyleActionSheet,这是所需的显示选项。 UIAlertControllerStyleAlert 显示所有 7 个,但我喜欢旧的 UIAlertControllerStyleActionSheet 外观。
在 iOS 10 下,如果您尝试设置警报控制器视图的 tintColor
,则显示样式为 "ActionSheet" 的 UIAlertController
无法正常工作。我 运行 在为 iOS 10 更新我的应用程序时遇到了这个问题。我向 Apple 提交了错误报告。
所以您的主要问题将通过不调用来解决:
[actionSheet.view setTintColor:[UIColor blackColor]];
下 iOS 10.
与此问题无关,您的代码错误地试图从各种警报操作中关闭警报控制器。不要这样做。警报将自动解除。您需要删除对以下内容的所有调用:
[actionSheet dismissViewControllerAnimated:YES completion:nil];