Such a problem. You need to add protocols (UIPickerViewDelegate, UIPickerViewDataSource) for the Picker View to get it working. At the same time, the Picker View itself is not on the start page, which is why an error is generated when compiling, since the attribute "self" is used (This, as I understood it). Here is the code:

class ViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource { @IBOutlet weak var imageView: UIImageView! @IBOutlet weak var pickerView: UIPickerView! let array = ["One", "Two"] override func viewDidLoad() { // Do any additional setup after loading the view, typically from a nib. super.viewDidLoad() pickerView.delegate = self pickerView.dataSource = self self.imageView.image = UIImage(named: "1club") } ....... 

Does anyone know how to deal with this?

I really hope for your help!

  • Does the text add error text? - AivanF.
  • Of course, this is: -> 0x1002425dc <+44>: brk # 0x1 fatal error: unexpectedly found nil while unwrapping an Optional value (lldb) - Mark
  • dropbox.com/s/yewijx2gyvsb193/App.zip?dl=0 here is the file for clarity - Mark
  • on which line it crashes? - Max Mikheyenko
  • pickerView.delegate = self pickerView.dataSource = self self.imageView.image = UIImage (named: "1club") These are the three. I think because I use the self attribute, and the picker itself is used on the second page. - Mark

1 answer 1

Everything is very running there: all 7 of the conrollers that are in the storyboard are listed as instances of the ViewController class. thus, when the first is loaded, there is no UIPickerView in it. As a result, when you try to assign a delegate and datasource in your code, you have the object UIPickerView == nil, and it turns out your error.

How to fix it?

Make 7 view controllers for each screen in the storyboard so that there is no such confusion.

  • DAAAAAH! Thank!!!! I sat on it for 4 hours, but everything turned out to be so simple! Now you can go to sleep with a pure soul :) Good projects to you, Max :) - Mark
  • do not forget to accept the answer - Max Mikheyenko