Вот мой код.Я пытаюсь использовать UIPickerview
для нескольких кнопок с разными данными.но это показывает, что у меня пустой серый вид выбора, когда я запускаю свой проект.некоторые говорили мне, что я должен перезагрузить pickerView, но я использовал его, например, "mainPV.delegate = self ..... Пожалуйста, мне нужна помощь, ребята, если кто-то может помочь мне
import UIKit
class SearchBuyVC: UIViewController {
@IBOutlet weak var optionV: UIView!
@IBOutlet weak var doneBtn: UIButton!
@IBOutlet weak var searchBtn: UIButton!
// picker view
@IBOutlet var mainPV: UIPickerView! // main
@IBOutlet var secPV: UIPickerView! //type
@IBOutlet var minPV: UIPickerView! //priceMin
@IBOutlet weak var typeBtn: UIButton!
@IBOutlet weak var PriceMinBtn: UIButton!
var optionSelector = 0
let searchData = ["Search by Areas", "Search by Map", "Search by LRT/MRTs", "Search by Schools", "Search by Propery Name"]
let typeData = ["All Residental", "All Commerical"]
let minNum = ["Any", "100 k", "200 k", "300 k", "400 k", "500 k", "600k ", "700 k"]
override func viewDidLoad() {
super.viewDidLoad()
setUpNav(arrowType: 2)
mainPV = UIPickerView()
secPV = UIPickerView()
minPV = UIPickerView()
mainPV.delegate = self
secPV.delegate = self
minPV.delegate = self
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
//Dispose of any resources that
}
override func viewDidAppear(_ animated: Bool) {
self.navigationController?.setNavigationBarHidden(false, animated: true)
}
@IBAction func selectOptionsPressed(_ sender: Any) {
openOptions()
mainPV.delegate = self
secPV.delegate = self
minPV.delegate = self
}
@IBAction func typeSelect(_ sender: Any) {
openOptions()
mainPV.delegate = self
secPV.delegate = self
minPV.delegate = self
}
@IBAction func minPriceBtn(_ sender: Any) {
openOptions()
mainPV.delegate = self
secPV.delegate = self
minPV.delegate = self
}
@IBAction func donePressed(_ sender: Any) {
switch optionSelector {
case 0:
FiltersController.instance.showAreaFilter(nc: self.navigationController!)
case 1:
FiltersController.instance.showMapFilter(nc: self.navigationController!)
case 2:
FiltersController.instance.showTrainStations(nc: self.navigationController!)
case 3:
FiltersController.instance.showSchoolFilter(nc: self.navigationController!)
default:
FiltersController.instance.showNameFilter(nc: self.navigationController!)
}
closeOptions()
}
func openOptions() {
optionV.isHidden = false
mainPV.isHidden = false
minPV.isHidden = false
doneBtn.isHidden = false
secPV.isHidden = false
}
func closeOptions(){
optionV.isHidden = true
mainPV.isHidden = true
minPV.isHidden = true
doneBtn.isHidden = true
secPV.isHidden = true
}
@IBAction func nextPressed(_ sender: Any) {
ListingController.instance.showBuyListing(nc: self.navigationController!)
}
}
extension SearchBuyVC: UIPickerViewDelegate, UIPickerViewDataSource {
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
if pickerView == mainPV {
return searchData.count
}
return 1
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
if pickerView == mainPV{
return searchData[row]
}
if pickerView == secPV{
return typeData[row]
}
if pickerView == minPV{
return minNum[row]
}
return ""
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
optionSelector = row
if pickerView == mainPV{
searchBtn.setTitle(searchData[row], for: .normal)
}
if pickerView == secPV{
typeBtn.setTitle(typeData[row], for: .normal)
}
if pickerView == minPV{
PriceMinBtn.setTitle(minNum[row], for: .normal)
}
}
}