首页 > 解决方案 > 如何快速更改非 viewController 类中的 ViewController?

问题描述

我在应用程序中使用 ble。当我点击一个启动 ble 的按钮时,BluetoothController 类正在工作。它工作得很好,但是当进入连接设备的过程时,我想显示可以连接的设备。所以我制作了一个包含 tableview 的新 ViewController。并创建了一个设备,称为 ViewController。但是当调用那个类时,我得到了“展开可选值”错误。我知道错误发生的时间。但我不知道为什么以及在哪里是零。

起初在蓝牙控制器中,我得到了presentedView。因为它不是 ViewController。

var topController = UIApplication.shared.keyWindow!.rootViewController!
            if topController.presentedViewController != nil
            {
                topController = topController.presentedViewController!
            }
            topController.show(bv!, sender: nil)

发生错误的 ViewController 包含 tableview。

BleAlertTableView.dataSource = self

我认为 AlertViewController(contain tableview) 无关紧要。我认为 topController 和改变 ViewController 的方法可能很重要。

标签: iosswiftxcodeuitableviewoptional

解决方案


推荐阅读