我的应用中有两个视图控制器,我尝试做的是将选择器视图数据带到“CallCamp”#39;按钮,然后为每个选定的行(仅三行)调用不同的数字
注意:选择器视图和按钮位于不同的ViewControllers中。
所以在这里我到目前为止,我不认为语法是正确的,但这里是:
@IBAction func CallComp(_ sender: UIButton) {
let PickerRows = self.storyboard?.instantiateViewController(withIdentifier: "firstViewController") as? firstViewController
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int)
{ let r1 = pickerView.selectedRow(inComponent:0)
let r2 = pickerView.selectedRow(inComponent: 1)
let r3 = pickerView.selectedRow(inComponent: 2)
var rows = [r1,r2,r3]
if r1 == true {if let phoneCallURL:NSURL = NSURL(string: "tel://\(900)") {
let application:UIApplication = UIApplication.shared
if (application.canOpenURL(phoneCallURL as URL)) {
application.openURL(phoneCallURL as URL);
}
}
}
if r2 == true {if let phoneCallURL:NSURL = NSURL(string: "tel://\(909)") {
let application:UIApplication = UIApplication.shared
if (application.canOpenURL(phoneCallURL as URL)) {
application.openURL(phoneCallURL as URL);
}
}
}
else if r3 == true {if let phoneCallURL:NSURL = NSURL(string: "tel://\(999)") {
let application:UIApplication = UIApplication.shared
if (application.canOpenURL(phoneCallURL as URL)) {
application.openURL(phoneCallURL as URL);
}
}
}}
代码中存在许多错误,但我希望您了解我需要的内容
答案 0 :(得分:-1)
rows
被定义为Int
的数组,您的切换案例为Int
您实际上并没有根据pickerView选择做任何事情 - 您是否尝试过一些pickerView教程?