UIView numberOfComponentsInPickerView unrecognized selector sent to instance

819 Views Asked by At

I know there's many questions for this issue out there, but I still cannot get my specific code to work. Sorry if this is noob question. This is literally my entire code below. If I break inside viewDidLoad my delegate and dataSource sets to self run without issue. The exception happens immediately after this event before any of the implemented UIPickerViewDataSource functions have a change to run. I included the debug below.

class ViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate {
    var listingTypesList:[String:Int] = [
        "Bench": 0,
        "Squat": 1,
        "Dead": 2
    ]

    @IBOutlet weak var listingType: UIPickerView!

    override func viewDidLoad() {
        super.viewDidLoad()

        listingType.delegate = self
        listingType.dataSource = self
    }

    func numberOfComponents(in pickerView: UIPickerView) -> Int {
        return 1
    }

    func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        return listingTypesList.count
    }

    func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
        var listingTypesArray = Array(listingTypesList.keys)
        return listingTypesArray[row]
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

2017-10-03 20:41:36.038930-0400 Lifting Trainer[328:19327] -[UIView numberOfComponentsInPickerView:]: unrecognized selector sent to instance 0x107811de0 2017-10-03 20:41:36.041055-0400 Lifting Trainer[328:19327] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView numberOfComponentsInPickerView:]: unrecognized selector sent to instance 0x107811de0' * First throw call stack: (0x181697d38 0x180bac528 0x1816a51f8 0x18ae5fcc4 0x18169d6e4 0x1815830dc 0x18acf93a8 0x18acf8504 0x18acf85e4 0x18aaa476c 0x18aaa445c 0x18aaa3918 0x18aaa3770 0x18aaaf39c 0x18aaae5c4 0x18aaab608 0x1a03c04fc 0x18ab1b068 0x18ad0a954 0x18ad0f6e4 0x18af9d454 0x18b26d1f0 0x18af9d0b8 0x18af9d928 0x18b7066e8 0x18b70658c 0x18b4829c0 0x18b617fc8 0x18b482870 0x18b26c850 0x18ad0de28 0x18b1116ec 0x183d39768 0x183d42070 0x105a6945c 0x105a75b74 0x183d6da04 0x183d6d6a8 0x183d6dc44 0x181640358 0x1816402d8 0x18163fb60 0x18163d738 0x18155e2d8 0x1833eff84 0x18ab0b880 0x1049993ac 0x18108256c) libc++abi.dylib: terminating with uncaught exception of type NSException

1

There are 1 best solutions below

0
On

I also had the same problem but I solved it using the code below:

override func viewDidLoad() {
    super.viewDidLoad()
    currencyPicker.delegate = self
    currencyPicker.dataSource = self
   
}