- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有两个下拉菜单,一个包含汽车品牌,一个包含汽车型号。当我选择汽车品牌时,是否可以过滤模型下拉列表中的值以仅显示与该特定品牌对应的值?
目前,当我从菜单中选择汽车品牌时,标题值将更改为所选的任何内容。我曾尝试将此值用作过滤模型选项的参数,但没有成功。希望我已经说得够清楚了:)
import UIKit
class ViewController: UIViewController {
////Set up buttons
var makeButton = makeDropDownBtn()
var modelButton = modelDropDownBtn()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically
from a nib.
makeButton = makeDropDownBtn.init(frame: CGRect(x: 0, y: 0,
width: 0, height: 0))
makeButton.setTitle("Select Make", for: .normal)
makeButton.titleLabel?.font = UIFont.boldSystemFont(ofSize:
17)
makeButton.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(makeButton)
makeButton.centerXAnchor.constraint(equalTo:
self.view.centerXAnchor).isActive = true
makeButton.centerYAnchor.constraint(equalTo:
self.view.centerYAnchor, constant: -300).isActive = true
makeButton.widthAnchor.constraint(equalToConstant:
450).isActive = true
makeButton.heightAnchor.constraint(equalToConstant:
50).isActive = true
makeButton.makeDropView.dropDownOptions = carMake
modelButton = modelDropDownBtn.init(frame: CGRect(x: 0, y: 0,
width: 0, height: 0))
modelButton.setTitle("Select Model", for: .normal)
modelButton.titleLabel?.font = UIFont.boldSystemFont(ofSize:
17)
modelButton.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(modelButton)
modelButton.centerXAnchor.constraint(equalTo:
self.view.centerXAnchor).isActive = true
modelButton.centerYAnchor.constraint(equalTo:
self.view.centerYAnchor, constant: -240).isActive = true
modelButton.widthAnchor.constraint(equalToConstant:
450).isActive = true
modelButton.heightAnchor.constraint(equalToConstant:
50).isActive = true
modelButton.modelDropView.modelDropDownOptions = carModel
}
}
protocol makeDropDownProtocol {
func makeDropDownPressed(string: String)
}
protocol modelDropDownProtocol {
func modelDropDownPressed(string: String)
}
class modelDropDownBtn: UIButton, modelDropDownProtocol {
func modelDropDownPressed(string: String) {
self.setTitle(string, for: .normal)
self.dismissModelDropDown()
}
var modelDropView = modelDropDownView()
var modelheight = NSLayoutConstraint()
override init(frame: CGRect) {
super.init(frame:frame)
self.backgroundColor = UIColor(red: 52/255, green: 49/255,
blue: 78/255, alpha: 1)
modelDropView = modelDropDownView.init(frame: CGRect(x: 0, y:
0, width: 0, height: 0 ))
modelDropView.modelDelegate = self
modelDropView.translatesAutoresizingMaskIntoConstraints =
false
}
override func didMoveToSuperview() {
self.superview?.addSubview(modelDropView)
self.superview?.bringSubviewToFront(modelDropView)
modelDropView.topAnchor.constraint(equalTo:
self.bottomAnchor).isActive = true
modelDropView.centerXAnchor.constraint(equalTo:
self.centerXAnchor).isActive = true
modelDropView.widthAnchor.constraint(equalTo:
self.widthAnchor).isActive = true
modelheight =
modelDropView.heightAnchor.constraint(equalToConstant: 0)
}
var isOpen = false
override func touchesBegan(_ touches: Set<UITouch>, with event:
UIEvent?) {
if isOpen == false {
isOpen = true
NSLayoutConstraint.deactivate([self.modelheight])
if self.modelDropView.modelTableView.contentSize.height >
150 {
self.modelheight.constant = 150
} else {
self.modelheight.constant =
self.modelDropView.modelTableView.contentSize.height
}
NSLayoutConstraint.activate([self.modelheight])
UIView.animate(withDuration: 0.5, delay: 0,
usingSpringWithDamping: 0.5, initialSpringVelocity: 0.5, options:
.curveEaseInOut, animations: {
self.modelDropView.layoutIfNeeded()
self.modelDropView.center.y +=
self.modelDropView.frame.height / 2
}, completion: nil)
} else {
isOpen = false
NSLayoutConstraint.deactivate([self.modelheight])
self.modelheight.constant = 0
NSLayoutConstraint.activate([self.modelheight])
UIView.animate(withDuration: 0.5, delay: 0,
usingSpringWithDamping: 0.5, initialSpringVelocity: 0.5,
options: .curveEaseInOut, animations: {
self.modelDropView.center.y -=
self.modelDropView.frame.height / 2
self.modelDropView.layoutIfNeeded()
}, completion: nil)
}
}
func dismissModelDropDown() {
isOpen = false
NSLayoutConstraint.deactivate([self.modelheight])
self.modelheight.constant = 0
NSLayoutConstraint.activate([self.modelheight])
UIView.animate(withDuration: 0.5, delay: 0,
usingSpringWithDamping: 0.5, initialSpringVelocity: 0.5, options:
.curveEaseInOut, animations: {
self.modelDropView.center.y -=
self.modelDropView.frame.height / 2
self.modelDropView.layoutIfNeeded()
}, completion: nil)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
class makeDropDownBtn: UIButton, makeDropDownProtocol {
func makeDropDownPressed(string: String) {
self.setTitle(string, for: .normal)
self.dismissMakeDropDown()
}
var makeDropView = makeDropDownView()
var height = NSLayoutConstraint()
override init(frame: CGRect) {
super.init(frame:frame)
self.backgroundColor = UIColor(red: 52/255, green: 49/255,
blue: 78/255, alpha: 1)
makeDropView = makeDropDownView.init(frame: CGRect.init(x: 0,
y: 0, width: 0, height: 0))
makeDropView.delegate = self
makeDropView.translatesAutoresizingMaskIntoConstraints = false
}
override func didMoveToSuperview() {
self.superview?.addSubview(makeDropView)
self.superview?.bringSubviewToFront(makeDropView)
makeDropView.topAnchor.constraint(equalTo:
self.bottomAnchor).isActive = true
makeDropView.centerXAnchor.constraint(equalTo:
self.centerXAnchor).isActive = true
makeDropView.widthAnchor.constraint(equalTo:
self.widthAnchor).isActive = true
height = makeDropView.heightAnchor.constraint(equalToConstant:
0)
}
var makeisOpen = false
override func touchesBegan(_ touches: Set<UITouch>, with event:
UIEvent?) {
if makeisOpen == false {
makeisOpen = true
NSLayoutConstraint.deactivate([self.height])
if self.makeDropView.tableView.contentSize.height > 150 {
self.height.constant = 150
self.superview?.bringSubviewToFront(makeDropView)
} else {
self.height.constant =
self.makeDropView.tableView.contentSize.height
}
NSLayoutConstraint.activate([self.height])
UIView.animate(withDuration: 0.5, delay: 0,
usingSpringWithDamping: 0.5, initialSpringVelocity: 0.5, options:
.curveEaseInOut, animations: {self.makeDropView.layoutIfNeeded()
self.makeDropView.center.y +=
self.makeDropView.frame.height / 2
}, completion: nil)
} else {
makeisOpen = false
NSLayoutConstraint.deactivate([self.height])
self.height.constant = 0
NSLayoutConstraint.activate([self.height])
UIView.animate(withDuration: 0.5, delay: 0,
usingSpringWithDamping: 0.5,initialSpringVelocity: 0.5, options:
.curveEaseInOut, animations: {
self.makeDropView.center.y -=
self.makeDropView.frame.height / 2
self.makeDropView.layoutIfNeeded()
}, completion: nil)
}
}
func dismissMakeDropDown() {
makeisOpen = false
NSLayoutConstraint.deactivate([self.height])
self.height.constant = 0
NSLayoutConstraint.activate([self.height])
UIView.animate(withDuration: 0.5, delay: 0,
usingSpringWithDamping: 0.5,initialSpringVelocity: 0.5, options:
.curveEaseInOut, animations: {
self.makeDropView.center.y -=
self.makeDropView.frame.height / 2
self.makeDropView.layoutIfNeeded()
}, completion: nil)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
/////Drop Down View Setup
struct Section {
var make: String
var model: [String]
}
var Cars = [
Section(make: "BMW", model: ["A","B","C"]),
Section(make: "Ford", model: ["D","E","F"]),
Section(make: "Audi", model: ["G","H","I"]),
Section(make: "Bentley", model: ["J","K","L"])
]
var carMake = Cars.map({$0.make})
var carModel = Cars.flatMap({$0.model})
class makeDropDownView: UIView,
UITableViewDelegate,UITableViewDataSource {
var dropDownOptions = [String]()
var tableView = UITableView()
var delegate : makeDropDownProtocol!
override init(frame: CGRect) {
super.init(frame: frame)
tableView.backgroundColor = UIColor.white
self.backgroundColor = UIColor.white
tableView.delegate = self
tableView.dataSource = self
tableView.translatesAutoresizingMaskIntoConstraints = false
self.addSubview(tableView)
tableView.leftAnchor.constraint(equalTo:
self.leftAnchor).isActive = true
tableView.rightAnchor.constraint(equalTo:
self.rightAnchor).isActive = true
tableView.topAnchor.constraint(equalTo:
self.topAnchor).isActive = true
tableView.bottomAnchor.constraint(equalTo:
self.bottomAnchor).isActive = true
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection
section: Int) -> Int {
return Cars.map({$0.make}).count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath:
IndexPath) -> UITableViewCell {
var cell = UITableViewCell()
cell.textLabel!.text = dropDownOptions[indexPath.row]
cell.backgroundColor = UIColor.init(red: 255/255, green:
160/255, blue: 122/255, alpha: 0.8)
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath:
IndexPath) {
self.delegate.makeDropDownPressed(string:
dropDownOptions[indexPath.row])
}
}
///model drop down view setup
class modelDropDownView: UIView, UITableViewDelegate,
UITableViewDataSource {
var modelDropDownOptions = [String] ()
var modelTableView = UITableView()
var modelDelegate : modelDropDownProtocol!
override init(frame: CGRect) {
super.init(frame: frame)
modelTableView.backgroundColor = UIColor.green
self.backgroundColor = UIColor.green
modelTableView.delegate = self
modelTableView.dataSource = self
modelTableView.translatesAutoresizingMaskIntoConstraints =
false
self.addSubview(modelTableView)
modelTableView.leftAnchor.constraint(equalTo:
self.leftAnchor).isActive = true
modelTableView.rightAnchor.constraint(equalTo:
self.rightAnchor).isActive = true
modelTableView.topAnchor.constraint(equalTo:
self.topAnchor).isActive = true
modelTableView.bottomAnchor.constraint(equalTo:
self.bottomAnchor).isActive = true
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection
section: Int) -> Int {
return Cars.flatMap({$0.model}).count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath:
IndexPath) -> UITableViewCell {
var modelCell = UITableViewCell()
modelCell.textLabel!.text =
modelDropDownOptions[indexPath.row]
modelCell.backgroundColor = UIColor.green
return modelCell
}
func makeselection(_ tableView: UITableView, didSelectRowAt
indexPath: IndexPath) {
self.modelDelegate.modelDropDownPressed(string:
modelDropDownOptions[indexPath.row])
}
}
希望可以根据我在制造商下拉列表中选择的制造商来过滤模型结果。提前致谢。
最佳答案
您不需要创建两个 UIButton 子类和两个 UIView 子类。您可以创建一个类并创建多个实例。
在选择品牌之前,不要为模型按钮设置 dropDownOptions。
选择品牌后,从所选品牌获取模型并在模型 dropDownOptions 中设置。
只需复制这段代码并运行。有效
/////Drop Down View Setup
struct Section {
var make: String
var model: [String]
}
var Cars = [
Section(make: "BMW", model: ["A","B","C"]),
Section(make: "Ford", model: ["D","E","F"]),
Section(make: "Audi", model: ["G","H","I"]),
Section(make: "Bentley", model: ["J","K","L"])
]
var carMake = Cars.map({$0.make})
class ViewController: UIViewController, DropDownBtnProtocol {
func optionChanged(_ button: DropDownBtn, string: String) {
if button == makeButton {
if let selectedMake = Cars.first(where: { $0.make == string }) {
modelButton.dropView.dropDownOptions = selectedMake.model
}
} else if button == modelButton {
}
}
////Set up buttons
var makeButton = DropDownBtn()
var modelButton = DropDownBtn()
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
makeButton = DropDownBtn.init(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
makeButton.delegate = self
makeButton.setTitle("Select Make", for: .normal)
makeButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: 17)
makeButton.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(makeButton)
makeButton.centerXAnchor.constraint(equalTo: self.view.centerXAnchor).isActive = true
makeButton.centerYAnchor.constraint(equalTo: self.view.centerYAnchor, constant: -300).isActive = true
makeButton.widthAnchor.constraint(equalToConstant: 450).isActive = true
makeButton.heightAnchor.constraint(equalToConstant: 50).isActive = true
makeButton.dropView.dropDownOptions = carMake
modelButton = DropDownBtn.init(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
modelButton.delegate = self
modelButton.setTitle("Select Model", for: .normal)
modelButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: 17)
modelButton.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(modelButton)
modelButton.centerXAnchor.constraint(equalTo: self.view.centerXAnchor).isActive = true
modelButton.centerYAnchor.constraint(equalTo: self.view.centerYAnchor, constant: -240).isActive = true
modelButton.widthAnchor.constraint(equalToConstant: 450).isActive = true
modelButton.heightAnchor.constraint(equalToConstant: 50).isActive = true
}
}
protocol DropDownBtnProtocol {
func optionChanged(_ button: DropDownBtn, string: String)
}
class DropDownBtn: UIButton, DropDownViewProtocol {
func dropDownPressed(string: String) {
self.setTitle(string, for: .normal)
self.dismissMakeDropDown()
delegate.optionChanged(self, string: string)
}
var delegate: DropDownBtnProtocol!
var dropView = DropDownView()
var height = NSLayoutConstraint()
override init(frame: CGRect) {
super.init(frame:frame)
self.backgroundColor = UIColor(red: 52/255, green: 49/255, blue: 78/255, alpha: 1)
dropView = DropDownView.init(frame: CGRect.init(x: 0, y: 0, width: 0, height: 0))
dropView.delegate = self
dropView.translatesAutoresizingMaskIntoConstraints = false
}
override func didMoveToSuperview() {
self.superview?.addSubview(dropView)
self.superview?.bringSubviewToFront(dropView)
dropView.topAnchor.constraint(equalTo: self.bottomAnchor).isActive = true
dropView.centerXAnchor.constraint(equalTo: self.centerXAnchor).isActive = true
dropView.widthAnchor.constraint(equalTo: self.widthAnchor).isActive = true
height = dropView.heightAnchor.constraint(equalToConstant: 0)
}
var makeisOpen = false
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if makeisOpen == false {
makeisOpen = true
NSLayoutConstraint.deactivate([self.height])
if self.dropView.tableView.contentSize.height > 150 {
self.height.constant = 150
self.superview?.bringSubviewToFront(dropView)
} else {
self.height.constant = self.dropView.tableView.contentSize.height
}
NSLayoutConstraint.activate([self.height])
UIView.animate(withDuration: 0.5, delay: 0,
usingSpringWithDamping: 0.5, initialSpringVelocity: 0.5, options:
.curveEaseInOut, animations: {self.dropView.layoutIfNeeded()
self.dropView.center.y += self.dropView.frame.height / 2
}, completion: nil)
} else {
makeisOpen = false
NSLayoutConstraint.deactivate([self.height])
self.height.constant = 0
NSLayoutConstraint.activate([self.height])
UIView.animate(withDuration: 0.5, delay: 0,
usingSpringWithDamping: 0.5,initialSpringVelocity: 0.5, options:
.curveEaseInOut, animations: {
self.dropView.center.y -= self.dropView.frame.height / 2
self.dropView.layoutIfNeeded()
}, completion: nil)
}
}
func dismissMakeDropDown() {
makeisOpen = false
NSLayoutConstraint.deactivate([self.height])
self.height.constant = 0
NSLayoutConstraint.activate([self.height])
UIView.animate(withDuration: 0.5, delay: 0,
usingSpringWithDamping: 0.5,initialSpringVelocity: 0.5, options:
.curveEaseInOut, animations: {
self.dropView.center.y -= self.dropView.frame.height / 2
self.dropView.layoutIfNeeded()
}, completion: nil)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
protocol DropDownViewProtocol {
func dropDownPressed(string: String)
}
class DropDownView: UIView, UITableViewDelegate,UITableViewDataSource {
var dropDownOptions = [String]() {
didSet {
tableView.reloadData()
}
}
var tableView = UITableView()
var delegate : DropDownViewProtocol!
override init(frame: CGRect) {
super.init(frame: frame)
tableView.backgroundColor = UIColor.white
self.backgroundColor = UIColor.white
tableView.delegate = self
tableView.dataSource = self
tableView.translatesAutoresizingMaskIntoConstraints = false
self.addSubview(tableView)
tableView.leftAnchor.constraint(equalTo: self.leftAnchor).isActive = true
tableView.rightAnchor.constraint(equalTo: self.rightAnchor).isActive = true
tableView.topAnchor.constraint(equalTo: self.topAnchor).isActive = true
tableView.bottomAnchor.constraint(equalTo: self.bottomAnchor).isActive = true
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return dropDownOptions.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath:
IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
cell.textLabel!.text = dropDownOptions[indexPath.row]
cell.backgroundColor = UIColor.init(red: 255/255, green: 160/255, blue: 122/255, alpha: 0.8)
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
self.delegate.dropDownPressed(string: dropDownOptions[indexPath.row])
}
}
关于arrays - 尝试根据在另一个下拉菜单中选择的值快速过滤一个下拉菜单中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56101323/
场景 网站页面有一个带有分页、过滤、排序功能的表格 View 。 表中的数据是从REST API服务器获取的,数据包含数百万条记录。 数据库 REST API 服务器 Web 服务器 浏览器 问
我有一个表student,其中的列dte_date(日期)具有值(2019-01-01、2019-02-01、2019-03-01)。 .等) 条件: dte_date 列中没有重复值。 但 dte_
我有一些逻辑可以根据不活动的用户创建通知。我正在获取具有以下属性的用户列表。我想做的只是在部门有非 Activity 用户时触发我的创建通知方法。因此,给出下面的列表,基本上会创建 1 个通知,表示部
使用 GPS 开发跟踪应用程序。一切都很好,但有时由于封闭区域或恶劣天气,我得到的分数不准确。当您绘制它们时,它看起来不对,有很多跃点/跳跃。 我应该运行什么算法来过滤掉不良信号对我来说,这看起来像是
我正在尝试按变量类型过滤对象数组。节点是一个具有位置的对象,但以不同的方式定义——作为点、矢量或附件。这是一个代码: class Joint { var position:Position
我想做的是在向量上创建一个过滤器,以便它删除未通过谓词测试的元素;但不太确定我该怎么做。 我根据谓词评估输入向量中的每个元素,例如在我的代码中,is_even 仿函数在 device_vector 向
我是 Gremlin 的新手,我正在使用 Gremlin 3.0.2 和 Stardog 5.0。我编写此查询是为了找出 schema.org 本体中两个实体之间的路径。以下是输出 - gremlin
考虑以下示例数据表, dt 30 的那一行需要去 - 或者如果其中两行 > 30相隔几秒钟,删除所有 3 个。然而 ,当我们有 4 行或更多行时,我们需要删除时间差 > 30 没有另一对 < 30
我正在考虑使用 ZeroMQ,并尝试了一些示例。但是,我无法验证 ZeroMQ 是否支持一些重要的要求。我希望你能帮助我。 我将使用这个简单的场景来问我的问题: 出版商(例如交易所)提供(大量)股票的
我需要从我的查询中过滤掉大量的对象。目前,它正在抓取类中的所有对象,我想将其过滤为查询字符串中的相关对象。我怎样才能做到这一点?当我尝试时,我收到一个属性错误说明 ''QuerySet' object
如何在 Prometheus 查询中添加标签过滤器? kube_pod_info kube_pod_info{created_by_kind="ReplicaSet",created_by_name=
我有包含字符串的列的数据框,并希望过滤掉包含某些字符串以外的任何内容的所有行。考虑下面的简化示例: string % dplyr::filter(stringr::str_detect(string,
我有以下数据框,其中包含多行的角度变化值: 'data.frame': 712801 obs. of 4 variables: $ time_passed: int 1 2 3 4 5 6
我有一个 BehaviorSubject我希望能够filter ,但要保持新订阅者在订阅时始终获得一个值的行为主题式质量,即使最后发出的值被过滤掉。有没有一种简洁的方法可以使用 rxjs 的内置函数来
我有一个 RSS 提要,每天输出大约 100 篇文章。我希望过滤它以仅包含更受欢迎的链接,也许将其过滤到 50 个或更少。回到当天,我相信您可以使用“postrank”来做到这一点,但在谷歌收购后现已
我有这样一个重复的xml树- this is a sample xml file yellowred blue greyredblue 如您所见,每个项目可以具有不同数量的颜色标签
我以为我在 Haskell 学习中一帆风顺,直到... 我有一个 [[Int]] tiles = [[1,0,0] ,[0,1,0] ,[0,1,0]
我在使用 Knockout.js 过滤可观察数组时遇到问题 我的js: 包含数据的数组 var docListData = [ { name: "Article Name 1", info:
我在 mongoDB 中有这个架构: var CostSchema = new Schema({ item: String, value: Number }); var Attachm
给定一个数据框“foo”,我如何才能只选择“foo”中的那些行,例如foo$location =“那里”? foo = data.frame(location = c("here", "there",
我是一名优秀的程序员,十分优秀!