我想在swift中的pickerview中选择多行 这是单行选择
`import UIKit
类ViewController:UIViewController,UIPickerViewDelegate,UIPickerViewDataSource {
@IBOutlet weak var titlelabel: UILabel!
@IBOutlet weak var pickerview: UIPickerView!
var cars = ["benz","audi","lombagini","rangerrover","bently"]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
pickerview.delegate = self
pickerview.dataSource = self
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return cars.count
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String! {
return cars[row]
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
titlelabel.text = cars[row]
}
}`
是否有人想知道在选择器视图中选择多行
在objective-c AlPickerview中,但它无效。
答案 0 :(得分:0)
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 2
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
if component == 0{
return bloodgroup.count
}
else if component == 1 {
return districk.count
}
return 1
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
if component == 0{
return bloodgroup[row]
}
else if component == 1 {
return districk[row]
}
return ""
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
if component == 0{
print(bloodgroup[row])
}
else if component == 1 {
print(districk[row])
}
}