私はナビゲーションカスタムクラスを作成しました。私はそれを飾りたいと思っていました。私はNavDecoration.swiftクラスを取り、次のコードに示す宣言拡張を宣言しました。このバーコードもこの関数に追加しました。拡張子が、その与えるエラーはUISearchBarDelegateプロトコルに準拠しなければならない「UISearchBarDelegate拡張子を使用してviewControllerの検索バーの代理人を設定する方法は?
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
}}
私はそれをすべての準備ができて、いつ私がsearchBar.delegate =のViewControllerのは私に同じエラーを与えることあなたが代理人としてのUIViewControllerの代わりUINAvigationControllerを割り当てる「UISearchBarDelegate – IOSDev
を入力するタイプ「のUIViewController」を割り当てることができないことを好き行っています。拡張機能が上記のようなものであれば、searchBar.delegate = viewController.navigationControllerを設定する必要があります。 – stefos