gpt4 book ai didi

ios - 如何在键盘上单击搜索按钮时进行搜索?

转载 作者:搜寻专家 更新时间:2023-10-30 22:10:24 25 4
gpt4 key购买 nike

我的表格 View 标题中有一个搜索栏。为此,我正在使用 uisearchcontroler。但是当我在搜索栏中发短信时它会更新 tablview 数据,我需要在单击键盘中的搜索按钮时更新 tablview,因为我在 api 中获取用于搜索的数据,并且每次我在搜索栏中发短信时它都会请求并且需要很长时间。我该如何解决这个问题?

var resultSearchController = UISearchController()
var indicator:UIActivityIndicatorView = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.Gray)
var ref=UIRefreshControl()
override func viewDidLoad() {
super.viewDidLoad()


self.resultSearchController = ({
let controller = UISearchController(searchResultsController: nil)
controller.searchResultsUpdater = self
controller.dimsBackgroundDuringPresentation = false
controller.searchBar.sizeToFit()

self.tableView.tableHeaderView = controller.searchBar

return controller
})()

indicator.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
indicator.center = view.center
view.addSubview(indicator)
indicator.bringSubviewToFront(view)

indicator.startAnimating()
UIApplication.sharedApplication().networkActivityIndicatorVisible = true

getRequests.getType1(tableView,spinner: indicator)

ref.addTarget(self, action: #selector(Catalog1TableViewController.refresh(_:)), forControlEvents: UIControlEvents.ValueChanged)
ref.attributedTitle = NSAttributedString(string: "Загрузка")
tableView.addSubview(ref)

}


func updateSearchResultsForSearchController(searchController: UISearchController)
{
indicator.startAnimating()
UIApplication.sharedApplication().networkActivityIndicatorVisible = true
tableView.reloadData()
getRequests.getProduct(tableView, spinner: indicator,name: searchController.searchBar.text!)
for item in getRequests.product {
if item.productTitle.containsString(searchController.searchBar.text!){
filteredTableData.append(item)
}

}
tableView.reloadData()
}

最佳答案

尝试实现 UISearchBar 委托(delegate)方法:

func searchBarSearchButtonClicked(searchBar: UISearchBar)

关于ios - 如何在键盘上单击搜索按钮时进行搜索?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38300445/

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