0

I have a code I am writing and its going well but I am having trouble with UISliders...specifically...setting values. I have used the sliders and now I want to reset them to the original state (0 to 10 with a value of 0 and the slider all the way to the left. I have...

@IBOutlet weak var redHorizontalSlider: UISlider!

Inside viewDidLoad:

    redHorizontalSlider!.minimumValue = 0.0
    redHorizontalSlider!.maximumValue = 1.0
    redHorizontalSlider!.setValue(0.0, animated: false)

and when I print the values its giving me a nil and an error:

Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value

I have played around with ! and ? in the declaration of the Object and the calls but to no avail.

pkamb
  • 33,281
  • 23
  • 160
  • 191
N. LaFave
  • 31
  • 7
  • 1
    Can you give more info about the error you're getting? Also, shouldn't your max value be 10? – Benjamin Lowry Oct 02 '16 at 23:24
  • sorry...I meant 1.0 in the first place. Here is the error message I get when I try to set any of the values (max, min or set value)... fatal error: unexpectedly found nil while unwrapping an Optional value (lldb) – N. LaFave Oct 03 '16 at 01:42
  • I used a ? and the errors went away but not the nil – N. LaFave Oct 03 '16 at 01:45
  • 1
    Possible duplicate of [What does "Fatal error: Unexpectedly found nil while unwrapping an Optional value" mean?](https://stackoverflow.com/questions/32170456/what-does-fatal-error-unexpectedly-found-nil-while-unwrapping-an-optional-valu) – pkamb Sep 21 '21 at 21:38

1 Answers1

1

This error is going to happen because the value of your slider is nil. Check your connections to make sure that your storyboard slider is connected to the slider variable.

Benjamin Lowry
  • 3,730
  • 1
  • 23
  • 27