1
func popUpList(title: String, PickerList: [String],index: Int, complistionHandler: @escaping (_ selectedValue: Int) ->()) {
let alertController = UIAlertController(title: nil, message: "\n\n\n\n\n\n\n", preferredStyle: .alert)
alertController.isModalInPopover = true;
let picker = UIPickerView(frame: CGRect(x: 0.0, y: 0.0, width: 250, height: 250))
picker.delegate = self
picker.dataSource = self
picker.selectRow(index, inComponent: 0, animated: true)
picker.showsSelectionIndicator = true
list = PickerList
picker.reloadAllComponents()
alertController.view.addSubview(picker)
let ok = UIAlertAction(title: "Ok", style: .default) { (alert) in
print(picker.selectedRow(inComponent: 0))
complistionHandler(picker.selectedRow(inComponent: 0))
}
alertController.addAction(ok)
let cancel = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
alertController.addAction(cancel)
self.present(alertController, animated: true, completion: nil);
}
このコードは常に値= 3を返している中をしかし、私は選択されたインデックスの値を取得したいです。助けてくださいここに私を助けてくださいは、それは常に同じインデックス「(inComponent:0)picker.selectedRow」戻っているSWIFTのiOS
ありがとう:) – hatim