【发布时间】:2016-05-25 13:02:14
【问题描述】:
我创建了导航自定义类,我想装饰它,我使用 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, target: viewController, action: "addTapped")
viewController.navigationItem.rightBarButtonItems = [add, play]
let left = UIBarButtonItem(barButtonSystemItem: .Add, target: viewController, action: "addTapped")
viewController.navigationItem.leftBarButtonItems = [left]
let searchBar = UISearchBar(frame: CGRectZero)
searchBar.placeholder = "Search"
searchBar.delegate = viewController
viewController.navigationItem.titleView = searchBar
}}
【问题讨论】:
标签: ios objective-c iphone cocoa-touch swift2