gpt4 book ai didi

ios - 从不同的pickerView中获取值(value)

转载 作者:行者123 更新时间:2023-11-30 13:52:09 24 4
gpt4 key购买 nike

目前我正在使用 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])"
}

}

我真的希望有人能帮助我度过这个难关。谢谢。

最佳答案

首先你有 7 个 pickerview。

@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 继续进行相同的操作。

关于ios - 从不同的pickerView中获取值(value),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34129169/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com