我是编程新手,所以请原谅这个问题的基本性质。
我正在尝试将多个选择器视图放入同一个类中,但他们会继续使用相同的选择。
class ViewController: UIViewController, UIPickerViewDelegate{
@IBOutlet var outgoing: UIPickerView!
var var1=["1","2"]
var var2=["a","b"]
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func numberOfComponentsInPickerView(pickerView: UIPickerView!) ->Int{
return 2
}
func pickerView(pickerView: UIPickerView!, numberOfRowsInComponent component: Int) ->Int {
return var1.count
}
func pickerView(pickerView: UIPickerView!, titleForRow row: Int, forComponent component: Int)->String!{
return var2[row]
}
有什么建议吗?
答案 0 :(得分:0)
要显示两个组件,您需要更改方法,如:
func numberOfComponentsInPickerView(pickerView: UIPickerView!) ->Int
{
return 2
}
func pickerView(pickerView: UIPickerView!, numberOfRowsInComponent component: Int) ->Int
{
var rows = var2.count
if component == 0
{
rows = var1.count
}
return rows;
}
func pickerView(pickerView: UIPickerView!, titleForRow row: Int, forComponent component: Int)->String!
{
var componentStr = var2[row]
if component == 0
{
componentStr = var1[row]
}
return componentStr;
}