I want to add a UISegmentedControl to a view controller and this is the corresponding code:
import UIKit
class QuantityNoImageViewController: UIViewController {
var food: Food!
@IBOutlet weak var foodName: UILabel!
@IBOutlet weak var message1: UILabel!
@IBOutlet weak var message2: UILabel!
@IBOutlet weak var message3: UILabel!
@IBOutlet weak var segmentControl: UISegmentedControl!
@IBAction func segmentControlPressed(_ sender: UISegmentedControl) {
switch segmentControl.selectedSegmentIndex {
case 0: print("one");
case 1: print("two");
case 2: print("three")
default: break;
}
}
@IBOutlet segmentControl as well as @IBAction segmentControlPressed are properly set.
When I run the app, all goes nicely until I press a segment which produces:
2017-12-15 17:22:11.840952+0100 Healthier[3835:248257] -[Healthier.QuantityNoImageViewController segmentedControl1:]: unrecognized selector sent to instance 0x7fc52e03ae00 2017-12-15 17:22:11.863471+0100 Healthier[3835:248257] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Healthier.QuantityNoImageViewController segmentedControl1:]: unrecognized selector sent to instance 0x7fc52e03ae00' *** First throw call stack:
I just cannot find any pointer that help me to solve this apparently simple bug. Could you please provide me some assistance?
You may have connected, multiple connections with this action (Exact I mean, you have copied this segment control from other screen and its previous connection is still not disconnected)
Reset/remove all IBAction connections with this segment and re-connect.
Storyboard/XIB >> View Controller >> Connection Inspector >> Reset all IBActions for segment control
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With