我有一个 UINavigationController,在其中我推送了一个具有 UIModalPresentationPageSheet 呈现样式的 View Controller 。
在此页表的 View Controller 中,我呈现了一个具有 UIModalPresentationFormSheet 样式的 View Controller 。
当用户点击表单上的“完成”按钮时,我想关闭表单和页面表。
在“完成”按钮上的操作中:
-(IBAction)onDone:(id)sender
{
if(self->delegate && [self->delegate respondsToSelector:self->actionSelector])
{
[self->delegate performSelector:self->actionSelector withObject:[NSString stringWithString:self.textView.text]];
}
[self dismissViewControllerAnimated:YES completion:nil];
}
委托(delegate)是页面表的 View Controller ,在选择器中,我关闭页面表:
[self dismissViewControllerAnimated:YES completion:nil];
当我运行它时,我得到:
Warning: Attempt to dismiss from view controller <UINavigationController: 0xa9381d0> while a presentation or dismiss is in progress!
我可以明白为什么会发生这种情况 - 因为在表单 View 被关闭之前调用选择器,但我不知道解决这个问题的最佳方法。
我尝试删除onDone中的dismiss,并在选择器调用中调用dismiss(对于表单使用animated:NO),它似乎起作用了,但我不知道这是否是这样的我应该解决它。
最佳答案
尝试在页面上调用dismissViewControllerAnimated:completion:。根据苹果的文档:
“如果连续呈现多个 View Controller ,从而构建呈现的 View Controller 的堆栈,则在堆栈中较低的 View Controller 上调用此方法会解除其直接 subview Controller 以及堆栈中该 subview 之上的所有 View Controller 。当这种情况发生时,只有最顶层的 View 以动画方式被消除;任何中间 View Controller 都只是从堆栈中删除。最顶层的 View 使用其模态转换样式被消除,这可能与其他 View 使用的样式不同查看堆栈中较低的 Controller 。”
如果这不完全是您想要的行为,那么您应该在dismissViewControllerAnimated:completion:中使用完成处理程序参数来传递一个 block ,然后从完成处理程序中关闭另一个 View Controller ,例如:
[formSheetViewController dismissViewControllerAnimated:YES completion:^{
[pageSheetViewController dismissViewControllerAnimated:YES competion:nil];
}
虽然说真的,我认为只要忽略页面表就可以解决你的问题。了解完成处理程序如何工作仍然很有好处。它可以让你在操作完成后做一些工作——非常方便。
关于ios - Objective-C - 同时关闭表单和页面表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17618913/