我创建了导航自定义类,我想装饰它,我拿了NavDecoration.
swift类并声明了下面代码中显示的扩展,我在这个函数中添加了搜索条形码,我想在这个扩展中设置搜索栏代理但是它的给定错误不能指定类型’UIViewController’来键入’UISearchBarDelegate
extension UINavigationController { func makeBlackNavigationbar (viewController: UIViewController,animated: Bool) { viewController.navigationController?.navigationBar.backgroundColor? = UIColor.blackColor() let add = UIBarButtonItem(barButtonSystemItem: .Add,target: viewController,action: "addTapped") let play = UIBarButtonItem(title: "Play",style: .Plain,action: "addTapped") viewController.navigationItem.rightBarButtonItems = [add,play] let left = UIBarButtonItem(barButtonSystemItem: .Add,action: "addTapped") viewController.navigationItem.leftBarButtonItems = [left] let searchBar = UISearchBar(frame: CGRectZero) searchBar.placeholder = "Search" searchBar.delegate = viewController viewController.navigationItem.titleView = searchBar }}
解决方法
您必须符合UISearchBarDelegate协议:
extension UINavigationController : UISearchBarDelegate { ... }