0

I have one pickerview already on a viewcontroller then I have a new viewcontroller which I have tried to enter a new pickerview however everytime I test my code I get a SIGABRT error. I know it must be something to do with the fact that I already am using those functions for my first one or something but I have no idea what to do here. Any help in the right direction would be nice.

Thanks

class ViewController2: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {

@IBOutlet var pickerView2: UIPickerView!

var aparray = ["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30"]



override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    pickerView2.delegate = self
   pickerView2.dataSource = self


}

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




func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
    return aparray[row]
}

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

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

}

class ViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {

@IBOutlet var pickerView: UIPickerView!

var array = ["1","2","3","4","5","6"]



override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    pickerView.delegate = self
   pickerView.dataSource = self


}

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




func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
    return array[row]
}

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

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

}

CRASH DATA BELOW:

2016-11-29 20:12:19.441114 testapp[1950:449604] Unknown class Vc2 in Interface Builder file.

2016-11-29 20:12:19.443065 testapp[1950:449604] * Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key pickerView2.' * First throw call stack: (0x193a7e1c0 0x1924b855c 0x193a7de88 0x194488110 0x199bda758 0x199ddc0c8 0x19399ddc4 0x199ddaa9c 0x199c3b444 0x199a0d53c 0x1998d8d48 0x1998d8c78 0x1998df424 0x1998dc8c4 0x19994f0e8 0x199b5ba78 0x199b615c8 0x199b75e60 0x199b5e5ac 0x1956258bc 0x195625728 0x195625ad0 0x193a2c278 0x193a2bbc0 0x193a297c0 0x193958048 0x1999442b0 0x19993f034 0x1000fac24 0x19293c5b8) libc++abi.dylib: terminating with uncaught exception of type NSException

  • please show current code and errors – Kayla Galway Nov 30 '16 at 00:22
  • I have two view controllers view controller already has a functional uipickerview that works fine however when I tried to implement the second uipickerview on the second viewcontroller2 the app crashes with the SIGABRT error. – William Lloyd Nov 30 '16 at 01:06
  • 1
    You are allowed to have two different picker views in two different classes and use those delegate methods again. They will not affect each other. When does the app crash? Right when you open view controller 2 ? Or when you click open the picker? Does anything print in the debugger? If not, set an exception breakpoint and show errors. – Kayla Galway Nov 30 '16 at 01:27
  • I have a button that takes me to the second view controller when I click it the app crashes. When I remove the second picker and all the data and click the button the app does not crash and takes me to the second view controller scene. The crash data should be uploaded at the bottom but to be honest I have a tough time making sense of it all, still learning that stuff. – William Lloyd Nov 30 '16 at 02:10
  • Possible duplicate of http://stackoverflow.com/questions/3088059/what-does-this-mean-nsunknownkeyexception-reason-this-class-is-not-key-v?s=1|15.0555 – rmaddy Nov 30 '16 at 06:20

1 Answers1

0

I just made my own project and compared it to your code, and unless I'm missing some very tiny typo, you are doing everything correctly. This makes me think there is an issue with either your x code project being glitchy, or a storyboard outlet is no longer connected.

Try to fully quit Xcode and then reopen, click product and then clean.

If that doesn't work, check your storyboard outlets. When you control click on your pickerView2 in storyboard, it should show you the outlets it is connected to.

In this case, there should only be one Referencing Outlet and the circle all the way to the right of it should be filled in white(like it is in the picture below).

If it is not filled in white, delete it because it is causing the crash. Then delete the code outlet. Then recreate the outlet.

enter image description here

It looks like you are doing everything right code wise. So if it continues being awful after the clean, and the outlet is connected correctly, delete the picker and all the code that references it and just recreate it.

Let me know if all of this still doesn't work for you. If it doesn't, screenshot your storyboard/viewcontrollers in interface builder like I did.

Kayla Galway
  • 662
  • 4
  • 7
  • Thanks Kayla, I will give this a whirl. Appreciate the help have a great night. – William Lloyd Nov 30 '16 at 03:00
  • Also, if it works, please mark my answer as correct! Thanks! – Kayla Galway Nov 30 '16 at 03:47
  • Hey Kayla, no luck on getting it to work I am really stumped on what is going on. I will continue to fool around with it but it still crashes and it has to do when I add that UIPickerView. When I remove it the app loads up. – William Lloyd Nov 30 '16 at 04:16
  • When you remove it from storyboard and remove all the code in the view controller that uses it - and then create an entirely new picker view on storyboard and a new outlet for that picker view in the code of the view controller class, it still crashes? – Kayla Galway Nov 30 '16 at 04:27
  • I edited the above with my debug crash data not sure what this means? – William Lloyd Nov 30 '16 at 05:48
  • That happens when an outlet is not connected correctly. It is telling you the outlet causing the issue is "pickerView2". Go to storyboard. Control click on view controller 2 and you'll see something just like what I screenshotted above. If there are any circles to the right of a pickerView2 outlet that are not filled in white, delete them – Kayla Galway Nov 30 '16 at 14:39
  • I renamed the viewcontroller custom class and made sure it matched my code. I was sure I had it all named properly before but for some reason this worked. Thanks again Kayla, your insight lead to the answer. Don't work too hard. ; ) – William Lloyd Nov 30 '16 at 17:00