Ios 使用UIPickerView从数组触发表填充
首先,如果我的思维过程完全错误,我道歉。我对这一切都很陌生,(老实说,距离我写第一行代码还不到两周!),但我认为我需要的功能应该是可能的 我正在尝试使用UIPickerView从40个选项中选择一个-然后,所选的值将触发一个小表的填充,其中包含来自第二个数组的值 到目前为止,我已成功添加并正确配置UIPickerView以读取第一个数组,并自动将选择器中选定项的值返回到UILabel(只是为了证明我从选择器获得了正确的输出) 考虑到我的业余性,我对自己很满意 基本上,这个初始数组包含40个组织的详细信息,我希望在选择一个组织时显示的表将在两列中包含6到8行。第一列是标题(地址、电话等),第二列是特定于该组织的值。 对于每个组织返回相同信息的所有条目,列将保持一致。在这方面,我希望这个问题对各位专家来说会比本来更简单 我的代码到目前为止Ios 使用UIPickerView从数组触发表填充,ios,arrays,swift,uitableview,uipickerview,Ios,Arrays,Swift,Uitableview,Uipickerview,首先,如果我的思维过程完全错误,我道歉。我对这一切都很陌生,(老实说,距离我写第一行代码还不到两周!),但我认为我需要的功能应该是可能的 我正在尝试使用UIPickerView从40个选项中选择一个-然后,所选的值将触发一个小表的填充,其中包含来自第二个数组的值 到目前为止,我已成功添加并正确配置UIPickerView以读取第一个数组,并自动将选择器中选定项的值返回到UILabel(只是为了证明我从选择器获得了正确的输出) 考虑到我的业余性,我对自己很满意 基本上,这个初始数组包含40个组织的
class ViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {
@IBOutlet weak var orgSelectedFromPicker: UILabel!
@IBOutlet weak var orgPicker: UIPickerView!
//function for the number of columns in the picker
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 1
}
//function counting the array to give the number of rows in the picker
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return orgPickerData.count
}
//function displaying the array rows in the picker as a string
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return orgPickerData[row]
}
//function allowing the font and colour of the picker to be changed
func pickerView(pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
let titleData = orgPickerData[row]
let myTitle = NSAttributedString(string: titleData, attributes: [NSFontAttributeName:UIFont(name: "Verdana", size: 15.0)!,NSForegroundColorAttributeName:UIColor.whiteColor()])
return myTitle
}
//function returning the selected row from the picker
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
self.orgSelectedFromPicker.text = orgPickerData[row]
}
//Array containing the list for UIPickerView
var orgPickerData = [...........] //I've taken the values out of here for privacy purposes..........]
override func viewDidLoad() {
super.viewDidLoad()
self.orgPicker.dataSource=self
self.orgPicker.delegate=self
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
`
有什么想法吗