目前我正在使用Xcode 7 Swift开发移动应用程序。我的应用程序使用pickerView。我有7个pickerView。
我想要做的是,按下按钮后获取每个pickerView的值。但我不知道怎么做。我还是Xcode和Swift的初学者。
这是我的编码
@IBOutlet weak var vomit: UIPickerView!
@IBOutlet weak var headache: UIPickerView!
@IBOutlet weak var muscle: UIPickerView!
@IBOutlet weak var abdominal: UIPickerView!
@IBOutlet weak var skin: UIPickerView!
@IBOutlet weak var bleeding: UIPickerView!
@IBOutlet weak var fever: UIPickerView!
var pickerVomit: [String] = [String]()
var pickerHead: [String] = [String]()
var pickerMuscle: [String] = [String]()
var pickerAbdominal: [String] = [String]()
var pickerSkin: [String] = [String]()
var pickerBleeding: [String] = [String]()
var pickerFever: [String] = [String]()
var vomitData = []
var headData = []
var muscleData = []
var abdominalData = []
var skinData = []
var BleedingData = []
var feverData = []
@IBAction func backMenu(sender: AnyObject) {
self.dismissViewControllerAnimated(true , completion: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
//Looks for single or multiple taps.
//let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "dismissKeyboard")
//view.addGestureRecognizer(tap)
vomitData = ["No","Yes"]
headData = ["No","Yes"]
muscleData = ["No","Yes"]
abdominalData = ["No","Yes"]
skinData = ["No","Yes"]
BleedingData = ["No","Yes"]
feverData = ["No","Yes"]
}
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
if (pickerView.tag == 1){
return vomitData.count
}
else if (pickerView.tag == 2){
return headData.count
}
else if (pickerView.tag == 3){
return muscleData.count
}
else if (pickerView.tag == 4){
return abdominalData.count
}
else if (pickerView.tag == 5){
return skinData.count
}
else if (pickerView.tag == 6){
return BleedingData.count
}
else {
return feverData.count
}
}
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
if (pickerView.tag == 1){
return "\(vomitData[row])"
}
else if (pickerView.tag == 2){
return "\(headData[row])"
}
else if (pickerView.tag == 3){
return "\(muscleData[row])"
}
else if (pickerView.tag == 4){
return "\(abdominalData[row])"
}
else if (pickerView.tag == 5){
return "\(skinData[row])"
}
else if (pickerView.tag == 6){
return "\(BleedingData[row])"
}
else {
return "\(feverData[row])"
}
}
我真的希望有人可以帮我解决这个问题。谢谢。
答案 0 :(得分:0)
首先,你有7个挑选者。
@IBOutlet weak var vomit: UIPickerView!
@IBOutlet weak var headache: UIPickerView!
@IBOutlet weak var muscle: UIPickerView!
@IBOutlet weak var abdominal: UIPickerView!
@IBOutlet weak var skin: UIPickerView!
@IBOutlet weak var bleeding: UIPickerView!
@IBOutlet weak var fever: UIPickerView!
7个数组包含根据pickerview的值。
var vomitData = []
var headData = []
var muscleData = []
var abdominalData = []
var skinData = []
var BleedingData = []
var feverData = []
现在,当点击按钮时,您希望所选行的每个选择器都有值!所以在按钮操作方法中添加以下代码,
let int_Vomit = self.vomit.selectedRowInComponent(0)
print("\(vomitData[row])")
继续使用其他pickerView。