gpt4 book ai didi

ios - Swift - 如何连接来自 UIPickerView 的 didSelectRow 选择

转载 作者:可可西里 更新时间:2023-11-01 00:58:27 24 4
gpt4 key购买 nike

我有一个两列选择器(英里和十分之一)

选择器似乎运行良好,但我似乎无法弄清楚如何连接两列的选择,即如果用户从第一列选择 23,从第二列选择 6,我想创建一个答案“23.6”

目前,任一列选择都会覆盖之前的选择。

顺便说一句:我不认为我可以附加两个字符串,因为如果用户先选择 10ths 会发生什么?

    let resetPickerData = [Array(0...99), Array(0...9)]

// returns the number of 'columns' to display.
func numberOfComponentsInPickerView(pickerView: UIPickerView!) -> Int{
return 2
}

// returns the # of rows in each component..
func pickerView(pickerView: UIPickerView!, numberOfRowsInComponent component: Int) -> Int{
return resetPickerData[component].count
}

func pickerView(pickerView: UIPickerView!, titleForRow row: Int, forComponent component: Int) -> String! {
return String(resetPickerData[component][row])
}

func pickerView(pickerView: UIPickerView!, didSelectRow row: Int, inComponent component: Int)
{
//var distance = ??
}

最佳答案

您需要像这样单独跟踪组件选择,然后连接字符串:

var firstComponentString = ""
var secondCompoentString = ""

func pickerView(pickerView: UIPickerView!, didSelectRow row: Int, inComponent component: Int)
{
if component == 0 {
firstComponentString = String(resetPickerData[component][row])
}
else if component == 1 {
secondCompoentString = String(resetPickerData[component][row])
}

var displayString = "\(firstComponentString).\(secondCompoentString)"
}

关于ios - Swift - 如何连接来自 UIPickerView 的 didSelectRow 选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39456758/

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