我有一个名为MenuDisplayable的协议类。该协议有一个扩展名。
protocol MenuDisplayable {}
extension MenuDisplayable where Self: UIViewController {
func showMenu( ) {
let storyboard = UIStoryboard(storyboard: .Menu)
let menuVC = storyboard.instantiateInitialViewController() as! MenuVC
present(menuVC, animated: true, completion: nil)
}
}
当我打电话给#34; showMenu"函数来自viewController类中的#selector
let rightButton = UIBarButtonItem(image: #imageLiteral(resourceName: "icon_hamb").withRenderingMode(.alwaysTemplate), style: .plain, target: self, action: #selector(StorySelectCarouselVC.showMenu) )
我收到错误,例如"' #selector'是指实例方法' showMenu()'没有暴露于Objective-C"
答案 0 :(得分:0)
您需要通过在{-1}}属性前添加前缀来声明Objective-C可访问的showMenu
方法。
objc