ios - Objective-C - 同时关闭表单和页面表

标签 ios objective-c uiviewcontroller dismiss uimodalpresentationstyle

我有一个 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/

相关文章:

ios - ARKIT 2.0 图像检测 : can't find when image disappear with ARImageTrackingConfiguration

ios - Swift xcode 错误 "cannot subscript a value of type ' [ListOfAnimals]'

ios - topLayoutGuide 在 vi​​ewWillAppear 之后应用

iphone - UIWindow rootViewController 的向后兼容性

ios - 我应该在哪里放置我的全局宏?

objective-c - NSString 时间格式转换为 int64_t

iphone - 我如何在 self.view 中调用这个方法?

objective-c - 如何创建一个将其大小保持在 objective-c 中的动态数组?

iphone - 来自相机的原始图像数据

iphone - View 和 View Controller