gpt4 book ai didi

ios - 如何使用扩展设置 viewController 搜索栏的委托(delegate)?

转载 作者:可可西里 更新时间:2023-11-01 03:32:46 24 4
gpt4 key购买 nike

我创建了导航自定义类,我想装饰它,我采用了 NavDecoration.swift 类并声明了如下代码所示的扩展,我也在这个函数中添加了搜索条码,我想在中设置搜索条委托(delegate)此扩展但其给出的错误无法将类型“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
}}

最佳答案

你必须遵守 UISearchBarDelegate 协议(protocol):

extension UINavigationController : UISearchBarDelegate {
...
}

关于ios - 如何使用扩展设置 viewController 搜索栏的委托(delegate)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37438007/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com