得到了一些很好的帮助,使得UIPickerView车轮工作得很好但是我一直试图让第二和第三个组件中的数据根据第一个组件的位置而变化。
我可以通过一些println行来确定我提取的whatConversion具有正确值的变量,但我不知道如何更改数组并使用新值进行UIPickerView更新。
请帮助我的理智,并且我将花费额外的时间在工作上花费几乎所有的时间在这些,十几行代码。
提前致谢
Motty
import UIKit
class ViewController: UIViewController, UIPickerViewDelegate {
@IBOutlet weak var picker1Label: UILabel!
@IBOutlet weak var picker2Label: UILabel!
@IBOutlet weak var bigPicker: UIPickerView!
var wheelContents:[[String]] = []
var length = ["metres","feet","yards","inches","mm","cm","miles"]
var volume = ["m3","US Gall","Imp Gall","Barrels", "cubic FT","litres"]
var conType = ["length","volume"]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
bigPicker.delegate = self
wheelContents = [conType, length, length]
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
//For main selection of type of conversion
// returns the number of 'columns' to display.
func numberOfComponentsInPickerView(bigPicker: UIPickerView) -> Int{
return wheelContents.count
}
// returns the # of rows in each component..
func pickerView(bigPicker: UIPickerView, numberOfRowsInComponent component: Int) -> Int{
return wheelContents[component].count
}
func pickerView(bigPicker: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String!{
return wheelContents[component][row]
}
func pickerView(bigPicker: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
var whatConversion = wheelContents[0][bigPicker.selectedRowInComponent(0)]
switch(whatConversion){
case "length":
wheelContents = [conType, length, length]
bigPicker.numberOfRowsInComponent(wheelContents[component].count)
break
case "volume":
wheelContents = [conType, volume, volume]
break
default:
break
}
}
}
答案 0 :(得分:3)
我更高兴我通过查看类定义和函数
来自己解决这个问题使用了bigPicker.reloadAllComponents()