Reputation: 55
When I run the application and click the Yes button, The application will crash. But the No button working fine. Did anyone know what is the error?
Here is the error:
2019-03-12 23:05:53.139631+0000 surveyPF[81734:12033947] -[UIView setText:]: unrecognized selector sent to instance 0x7fe1c4416eb0 2019-03-12 23:05:53.148796+0000 surveyPF[81734:12033947] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setText:]: unrecognized selector sent to instance 0x7fe1c4416eb0'
And here is my code:
import UIKit
class FirstQViewController: UIViewController {
var IDtext: String?
var DateText: String?
var answer: String?
@IBAction func viewBtn(_ sender: UIButton) {
switch sender.tag {
case 0: answer = "Yes"
self.performSegue(withIdentifier: "firstSegue", sender: self)
case 1: answer = "No"
self.performSegue(withIdentifier: "secondSegue", sender: self)
default:
print("Nothing")
}
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "firstSegue", let dest = segue.destination as? SecondQViewController {
dest.IDtext = self.IDtext
dest.DateText = self.DateText
dest.answer = self.answer
} else if segue.identifier == "secondSegue", let dest = segue.destination as? ThirdQViewController {
dest.IDtext = self.IDtext
dest.DateText = self.DateText
dest.answer = self.answer
}
}
}
Upvotes: 0
Views: 3079
Reputation: 14004
In my case the problem was like this (may be helpful for others as well)
We had an old Objective-C class, which subclassed the UITextField:
@interface CustomTextField: UITextField
On the storyboard, someone set Custom Class CustomTextField
on UIView. Somehow this was working fine for years.
But when we migrated CustomTextField
to Swift (pretty much one-to-one, no major changes were done), the UIView, which had Custom Class set to CustomTextField
started crashing with the same exception:
[UIView setText:]: unrecognized selector sent to instance ...
So the solution was to replace UIView on the storyboard with the actual UITextField
Upvotes: 0
Reputation: 318955
When you click Yes, you segue to an instance of SecondQViewController
. It seems that somewhere in that view controller you are setting the text
property of some view that you expect to have a text
property (such as a UILabel
, UITextField
, or UITextView
) but your storyboard for that view controller has that view set as a UIView
and not the more specific class type.
You need to check the views in the storyboard for the view controller and see which view is set as a plain old UIView
instead of a more specific type of view that actually has a text
property.
Upvotes: 3