我相信这是一个iOS8错误,但我不确定。我可以通过一个简单的项目轻松地重现它。
在iOS8上,我以模板方式呈现一个视图控件作为表单,然后在该表单中显示一个操作表。
- (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。有趣的是,如果你在动作表之外点击它就会被解雇,但是不会把它带到视图控制器上。
有没有办法解决这个问题?也许是一种在行动表之外“伪造”水龙头的方法?
这是一个简单的测试项目,演示了行为:https://www.dropbox.com/s/kecyi4egpckwn69/ActionsheetIssueTest.zip?dl=0
答案 0 :(得分:3)
UIAlertView和UIActionSheet已在iOS8中弃用。它们被UIAlertController取代。
为了更新现有代码,我发现运行良好的解决方法是替换委托方法的使用:
actionSheet:clickedButtonAtIndex:
使用委托方法:
actionSheet:didDismissWithButtonIndex:
这将确保在尝试呈现另一个视图控制器之前解除警报控制器。
我遇到了这个问题,因为选择了一个动作表,我试图提出一个模态。当选择带有操作表的照片来询问相机或照片时,这是一种常见的范例。使用didDismissWithButtonIndex:允许向后兼容iOS 7。
前进你应该拥抱UIAlertController。这里有一些阅读:
答案 1 :(得分:0)
这是Temporary Fix。在操作表委托方法中使用以下代码。
[self.presentedViewController dismissViewControllerAnimated:NO completion:nil];