【发布时间】:2018-07-20 13:35:11
【问题描述】:
我在SegmentControl 中创建了一个PickerView,我有两个单独的数组FirstArray 有StringData,第二个数组有NSNumber 数据。我需要返回两个数组,以便在同一行中以 StringData 和 Number 的形式返回。
For Example: First Array has : Ark,silk,temp etc, Second Array has 23,45,56 etc.
如果我在PickerView 中单独返回第一个数组,它会返回字符串值,但我需要显示两个数组。我已在选择器视图中显示一个数组,但不知道如何返回两个数组。
代码:
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
if (pickerView == EventsPickerView) {
// case EventsPickerView:
return EventArray.count
}else {
switch FabricSegmentControl.selectedSegmentIndex {
case 0:
return globalConstants.ClassificationName.count
// return globalConstants.ClassificationName.count + globalConstants.ClassificationCount.count
case 1:
return globalConstants.ClassificationNameSecond.count
default:
return 1
}
}
// return 1
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
if (pickerView == EventsPickerView){
// case EventsPickerView:
return EventArray[row]
}else {
switch FabricSegmentControl.selectedSegmentIndex {
case 0:
return globalConstants.ClassificationName[row] as? String
case 1:
return globalConstants.ClassificationNameSecond[row] as? String
default:
return "error occured"
}
}
// return "error occured"
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
if (pickerView == EventsPickerView){
eventTextField.text = EventArray[row]
}else {
switch FabricSegmentControl.selectedSegmentIndex {
case 0:
TypeOfSilkTextField.text = globalConstants.ClassificationName[row] as? String
case 1:
TypeOfSilkTextField.text = globalConstants.ClassificationNameSecond[row] as? String
default:
break
}
}
这些是我的数组名称
First Array :globalConstants.ClassificationName.count
SecondArray name :globalConstants.ClassificationCount.count
【问题讨论】:
-
如果两个数组中的数据属于一起,为什么不创建一个包含字符串和数字的结构,或者使用一个元组,然后有一个结构(或元组)的单个数组?跨度>
-
我会试试这个并更新。
标签: ios arrays swift uipickerview