I have some tableview cells loaded like this..
Here, the qty
field gets value from the picker field. But the issue is though both fields does show the picker fields, the data as per what is selected in the picker field is shown in the 2nd field only and in the 1st field, though I select a value from the picker field, that value is shown in the 2nd picker field instead of the 1st.
My picker view has 10 values defined in viewDidLoad
like so...
self.noOfItems = ["1","2","3","4","5","6","7","8","9","10"]
The picker view has been defined in my tableview cellForRowAt
like so...
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: sellTableViewCell = tableView.dequeueReusableCell(withIdentifier: "sellProductIdentifier") as! sellTableViewCell
cell.delegate = self
let pickerView = UIPickerView()
pickerView.delegate = self
cell.qtyPickerField.inputView = pickerView
cell.qtyPickerField.text = noOfItems[0]
if let cell = cell.qtyPickerField.superview?.superview as? sellTableViewCell {
myCell = cell
}
return cell
}
My picker view methods have been given like so...
//Picker view methods
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return noOfItems.count
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return noOfItems[row]
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
myCell.qtyPickerField.text = noOfItems[row]
}