Objective c 防止我的iOS 8 iPad操作单将其驳回';父视图控制器?

Objective c 防止我的iOS 8 iPad操作单将其驳回';父视图控制器?,objective-c,ipad,ios8,uiactionsheet,Objective C,Ipad,Ios8,Uiactionsheet,我相信这是一个iOS8错误,但我不确定。我可以用一个简单的项目很容易地复制它 在iOS8上,我以表单的形式呈现viewcontroller,然后在该表单中显示actionsheet - (IBAction)showActionSheet:(id)sender { UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"How can I stop the m

我相信这是一个iOS8错误,但我不确定。我可以用一个简单的项目很容易地复制它

在iOS8上,我以表单的形式呈现viewcontroller,然后在该表单中显示actionsheet

- (IBAction)showActionSheet:(id)sender {
UIActionSheet *actionSheet = [[UIActionSheet alloc]
                              initWithTitle:@"How can I stop the modal formsheet from being dismissed with the actionsheet?"
                              delegate:self
                              cancelButtonTitle:@"Cancel"
                              destructiveButtonTitle:@"Destructive"
                              otherButtonTitles:@"Another Button",nil];

[actionSheet showInView:self.view];
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
// Confirmation message is specific to the filter applied
NSLog(@"clicked %d",buttonIndex);

}
当此操作表根据用户选择自动取消时,它也将取消显示它的viewcontroller。有趣的是,如果在操作表外点击,它将被取消,但不会带上viewcontroller

有办法解决这个问题吗?也许是一种在行动表外“假装”窃听的方法


下面是一个简单的测试项目,演示了该行为:

这里是临时修复。在操作表委托方法中使用以下代码

[self.presentedViewController dismissViewControllerAnimated:NO completion:nil];

UIAlertView和UIActionSheet在iOS8中已被弃用。它们将替换为UIAlertController

对于更新现有代码,我发现有效的解决方法是替换委托方法的使用:

actionSheet:clickedButtonAtIndex:
actionSheet:didDismissWithButtonIndex: 
使用委托方法:

actionSheet:clickedButtonAtIndex:
actionSheet:didDismissWithButtonIndex: 
这将确保在尝试呈现另一个视图控制器之前解除警报控制器

我在任何地方都遇到了这个问题,因为我试图通过选择行动表来呈现模式。这是一个常见的范例,当选择一张带有行动表的照片来请求相机或照片时。使用didDismissWithButtonIndex:允许向后兼容iOS 7

向前看,你应该拥抱UIAlertController。以下是一些阅读材料:


我也看到了这一点。你有没有记录过苹果的bug?根据开发者论坛,已经有一个雷达打开了。我从未解决过这个问题,但直接使用iOS8 UIAlertController不会发生。因此,我在带有操作表设置的UIAlertController和直接UIActionsheets之间切换。谢谢。我也切换到了UIAlertController,但是如果他们修复了这个错误那就太好了。你这里指的是哪种委托方法?ClickedButtonIndex:在你的情况下。简言之,在您将任何控制器模态地呈现在副作用表中之前,请先编写上述代码。