ios - 在 Swift 上弹出 ViewController

标签 ios uinavigationcontroller swift

我需要从导航 Controller 中弹出一个 UIViewController。

只是写了这行代码却抛出了异常;

在展开可选值时意外发现 nil

self.navigationController.popViewControllerAnimated(true)

如果我将导航 Controller 设为可选,则此行无效,不会弹出

self.navigationController?.popViewControllerAnimated(true)

如何解决?

最佳答案

您需要正确解包您的 navigationController

if let navController = self.navigationController {
    navController.popViewController(animated: true)
}

关于ios - 在 Swift 上弹出 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25400476/

相关文章:

ios - 如果我在旋转设备 `insertRows` 时调用 "Incorrect checksum for freed object",UITableView 就会崩溃

ios - 如何配置我的应用程序以检测抖动运动事件?

ios - 如何将分段 Controller 按钮从 UILabel 更改为 UIImage?

ios - 构建目标随机添加到 Xcode 方案

iOS 13 Xcode 如何删除 UIKeyboard 上的 QuickType(自动完成/自动建议)

ios - 触摸已移动 : How to know when the touch ended?

objective-c - 将新的 TableView 添加到另一个 UINavigationController

ios - 截断应用程序中所有 UINavigationBar 标题的最佳方法

swift - 将 Tab Bar Controller 嵌入 Navigation Controller 时的 prepareForSegue

swift 陀螺仪 : Unexpectedly found nil while unwrapping an Optional value