此代码显示错误:“无法将'UIViewController.Type‘类型的值转换为预期的参数类型’UIViewController‘。请告诉我如何解决此问题。”
@objc static func listBtn()
{
drawerVw = DrawerView(aryControllers: DrawerArray.array, isBlurEffect: true, isHeaderInTop: false, controller: UIViewController.self)
//drawerVw = DrawerView(aryControllers: DrawerArray.array, isBlurEffect: true, isHeaderInTop: false, controller: self)
drawerVw.delegate = UIViewController.self as? DrawerControllerDelegate
//drawerVw.delegate = self
drawerVw.changeUserName(name: "New Delhi")
drawerVw.show()
}
发布于 2018-04-06 16:10:33
您需要使用此代码。这段代码在我这边运行得很好。
班级
@objc static func listBtn() {
UIViewController.showListButton(navigationController: navController)
}
扩展
import Foundation
import UIKit
extension UIViewController
{
static func showListButton(navigationController: UINavigationController)
{
if let currentVC = navigationController.visibleViewController
{
drawerVw = DrawerView(aryControllers: DrawerArray.array, isBlurEffect: true, isHeaderInTop: false, controller: currentVC)
drawerVw.delegate = currentVC as? DrawerControllerDelegate
drawerVw.show()
}
}
}
发布于 2019-04-11 03:42:25
如果您将变量设置为如下所示:
let vc = self.storyboard?.instantiateViewController(withIdentifier: "chatView") as? HomeViewController
它应该会删除该错误。
https://stackoverflow.com/questions/49686299
复制相似问题