gpt4 book ai didi

ios - 如何将segmentedControl和UISearchController作为UITableViewController header ? (以编程方式)

转载 作者:行者123 更新时间:2023-11-30 12:26:56 24 4
gpt4 key购买 nike

我创建了一个 UISearchController:let mySearchController = UISearchController(searchResultsController: nil) 和一个分段控件:

var mySegmentedControl: UISegmentedControl {
let items = ["One", "Two", "Three"]
let segmentedControl = UISegmentedControl(items: items)

return segmentedControl
}

我如何将这两个都作为我的 UITableViewController header ?我尝试将它们都放入 UIView 中,并将 UIView 设置为标题,但这样做时搜索栏不起作用。

这应该如何完成?

最佳答案

使用scopeButtonTitles属性:

mySearchController.searchBar.scopeButtonTitles = ["One", "Two", "Three"]

看看this question更多细节。

更新:添加了对scopeButton更改的响应:

func searchBar(_ searchBar: UISearchBar, selectedScopeButtonIndexDidChange selectedScope: Int) { 
// respond to your scopeBar selection here
switch selectedScope {
case 0:
print("tab One selected")
tableView.tintColor = UIColor.red
case 1:
print("tab two selected")
tableView.tintColor = UIColor.blue
case 2:
print("tab Three selected")
tableView.tintColor = UIColor.yellow
default:
print("Someone added a tab!")
}

关于ios - 如何将segmentedControl和UISearchController作为UITableViewController header ? (以编程方式),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44064937/

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