我几乎已经完成了我的应用,并且想尝试使用UIPicker选择其他UIViewController,即FirstViewController,SecondViewController,ThirdViewController。 去年我确实曾尝试找到一种解决方案,但找不到,所以我避免使用UIPicker。当我尝试使用UIPicker时发生错误,向上滚动它可以正常工作,因此在UIPicker上选择任何东西都可以,但是如果我不小心向下滚动到实际上没有任何选择的地方,则会崩溃,并且“没有提示”错误代码为“ CDM RegulationsSegue”的错误,现在我的第一个Segue称为Segue,这是我可以使其正常工作的唯一方法,但是如果向下滚动会崩溃,如果我将其命名为RegulationsSegue,它将无法运行。请在下面查看我的代码
描述我如何解决此问题的最简单方法是,我的Segues标识符命名正确,并且无法运行,但是如果我将我的第一个Segue命名为Segue则可以正常工作。但在UIPicker上意外滚动时仍会崩溃
class PaperWorkViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {
@IBOutlet weak var pickerView: UIPickerView!
var pickerData = ["CDM Regulations","CDM Duties","Request for Info"]
var selectedDetail = ""
override func viewDidLoad() {
super.viewDidLoad()
pickerView.delegate = self
pickerView.dataSource = 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.
}
@IBAction func continueButtonPressed(_ sender: AnyObject) {
self.performSegue(withIdentifier: "\(selectedDetail)Segue", sender: nil)
}
// The number of columns of data
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
// The number of rows of data
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return pickerData.count
}
// The data to return for the row and component (column) that's being passed in
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return pickerData[row]
}
//Called when the user changes the selection...
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
selectedDetail = pickerData[row]
}
// Capture the picker view selection
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
// This method is triggered whenever the user makes a change to the picker selection.
// The parameter named row and component represents what was selected.
}
}
UK [1886:403119] ***由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'接收器(
)没有标识为'CDM RegulationsSegue的segue' ***首先抛出调用堆栈:
如果我将Segue CDM法规命名为Segue,它将无法运行。