我关于选择器视图的问题。我有两个文本字段,它们是连接选择器视图,但是当我尝试进行选择时,这两个文本字段的文本变得相同。我已经尝试过将标签用于选择器视图,但是没有用。在这里我的代码可以更好的理解。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.section == 3 {
let cell = tableView.dequeueReusableCell(withIdentifier: "TextFieldCellTeslim", for: indexPath) as! TextFieldCellTeslim
let datePickerTeslim = UIPickerView()
datePickerTeslim.delegate = self
datePickerTeslim.dataSource = self
datePickerTeslim.backgroundColor = .white
cell.dateTextFieldTeslim.inputView = datePickerTeslim
datePickerTeslim.tag = indexPath.row
return cell
}
if indexPath.section == 2 {
let cell = tableView.dequeueReusableCell(withIdentifier: "TextFieldCell", for: indexPath) as! TextFieldCell
let datePicker = UIPickerView()
datePicker.delegate = self
datePicker.dataSource = self
datePicker.backgroundColor = .white
cell.dateTextField.inputView = datePicker
datePicker.tag = indexPath.row
return cell
}
这些代码向我们展示了选择器视图的连接。
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
if component == 0 {
secilenTarih = tarihArray[row]
let path = IndexPath.init(row: pickerView.tag, section: 2)
let cell = tableView.cellForRow(at: path) as? TextFieldCell
cell!.dateTextField.text = secilenTarih
let pathTeslim = IndexPath.init(row: pickerView.tag, section: 3)
let cellTeslim = tableView.cellForRow(at: pathTeslim) as? TextFieldCellTeslim
cellTeslim!.dateTextFieldTeslim.text = secilenTarih
}
if component == 1 {
secilenSaat = saatArray[row]
let path = IndexPath.init(row: pickerView.tag, section: 2)
let cell = tableView.cellForRow(at: path) as? TextFieldCell
cell!.dateTextField.text = secilenTarih + " " + secilenSaat
let pathTeslim = IndexPath.init(row: pickerView.tag, section: 3)
let cellTeslim = tableView.cellForRow(at: pathTeslim) as? TextFieldCellTeslim
cellTeslim!.dateTextFieldTeslim.text = secilenTarih + " " + secilenSaat
}
}
这是我的选择器视图扩展。我想分别选择这两个文本字段。我该如何做呢?我希望我问清楚。