无法关闭View控制器

时间:2019-10-04 18:50:06

标签: swift uiviewcontroller

我正在尝试关闭已显示为模式.overCurrentContext的View Controller。

这样显示控制器

let vc= UIViewController()
vc.modalPresentationStyle = .overCurrentContext
present(vc, animated: true, completion: nil)

当我在出现的vc控制器内调用dismiss时,它什么也没做。

要提供有关父级ViewController的更多详细信息,它是NavigationController内的ViewController,在NavigationController的VC堆栈中排名第三。

1 个答案:

答案 0 :(得分:0)

因此,实际的解决方案非常模糊。

我正在使用一个名为FloatingPanelController的Pod,该Pod间歇性地释放整个视图堆栈会导致一些问题。

为了解决它,我在Pod中修改了扩展名

public extension UIViewController {
@objc func fp_original_dismiss(animated flag: Bool, completion: (() -> Void)? = nil) {
    // Implementation will be replaced by IMP of self.dismiss(animated:completion:)
}
@objc func fp_dismiss(animated flag: Bool, completion: (() -> Void)? = nil) {
    // Call dismiss(animated:completion:) to a content view controller
    if let fpc = parent as? FloatingPanelController {
        if fpc.presentingViewController != nil {
            self.fp_original_dismiss(animated: flag, completion: completion)
        } else {
            fpc.removePanelFromParent(animated: flag, completion: completion)
        }
        return
    }
    // Call dismiss(animated:completion:) to FloatingPanelController directly
    if let fpc = self as? FloatingPanelController {
        if fpc.presentingViewController != nil {
            self.fp_original_dismiss(animated: flag, completion: completion)
        } else {
            fpc.removePanelFromParent(animated: flag, completion: completion)
        }
        return
    }

    // For other view controllers
    self.fp_original_dismiss(animated: flag, completion: completion)
}
}

我特别删除了最后一行:

    self.fp_original_dismiss(animated: flag, completion: completion)

这是导致问题的原因。我不知道该方法实际上是覆盖整个dismiss方法。一旦我重新插入该行,问题就解决了。

这对其他人来说几乎没有用!