-1

Im trying to implement a scrollView, pythoScroll, into my code! It runs but then i get runtime error and this message appears... "unexpectedly found nil while unwrapping an Optional value" and it points to these two lines inside my viewDidLoad. Thank you

   override func viewDidLoad() {
    super.viewDidLoad()

    pythoScroll.contentSize.height = 100
    pythoScroll.contentSize.width = 300

}
  • pythoScroll is nil, probably not connected in Interface Builder – Atamiri Sep 14 '15 at 03:12
  • 1
    Possible duplicate of [What does "fatal error: unexpectedly found nil while unwrapping an Optional value" mean?](http://stackoverflow.com/questions/32170456/what-does-fatal-error-unexpectedly-found-nil-while-unwrapping-an-optional-valu) – Aaron Brager Aug 03 '16 at 03:13

1 Answers1

0

You can setup your scroll view programmatically. It's better and neater in my opinion. To do so:

  1. Create a ScrollView variable just before your viewDidLoad()

    var scrollView = UIScrollView!

  2. Inside your viewDidLoad() do the following:

    scrollView = UIScrollView(frame: view.bounds) scrollView.contentSize = CGSize(width: 300, height: 300) view.addSubview(scrollView)

  3. That's pretty much it. To be honest I'm not on Xcode so I can't really test whether this code runs or not. Try it out, and if there are any issues let me know.