Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unrecognized selector sent using UISegmentedControl

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?

like image 734
jfboisvieux Avatar asked Jun 08 '26 15:06

jfboisvieux


1 Answers

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

like image 122
Krunal Avatar answered Jun 10 '26 07:06

Krunal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!