在Cordova插件中使用NavigationController推送视图

时间:2019-04-15 09:50:07

标签: swift cordova

我试图编写一个cordova插件来打开一个新的ViewController。导航栏是必需的(用于后退按钮),因此我想将viewcontroller包装在navigationcontroller中。

我试图在我的self.viewController.navigationController?类中从CDVPlugin推送VC。但是什么也没发生。该视图不显示。示例代码:

@objc(MyVCWrapper) class VCWrapper : CDVPlugin {
    @objc(openVC:) func openVC(_ command: CDVInvokedUrlCommand){
        // Init VC
        let vc = UIViewController()
        let backItem = UIBarButtonItem()
        backItem.title = ""
        vc.navigationItem.backBarButtonItem = backItem
        vc.hidesBottomBarWhenPushed = false

        // Show VC 
       self.viewController.navigationController?.pushViewController(vc, animated: true)

        // Return success message
        self.commandDelegate!.send(
            CDVPluginResult(
                status: CDVCommandStatus_OK,
                messageAs: "Success"
            ),
            callbackId: command.callbackId
        )
    }
}

如果我拨打self.viewController.present(vc, animated: true),它会起作用。但随后不存在导航栏。

有人知道解决方法还是我做错了什么?

0 个答案:

没有答案