-1

I am trying to add a button that allows the user to refresh the tableview and bring them back to the top of the table. I am trying to add a snippet of code that has a var set up like this var layoutGuide:UILayoutGuide! but it is giving me this message. first image I then try to run the simulator and simply ignore this message but then I get an error saying it has found an optional value nil when unwrapping it. error message Any ideas on why this is happening? Thank you

  • Does this answer your question? [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) – Chris Shaw Jan 16 '20 at 00:53
  • 1
    Should you be using `let layoutGuide = UILayoutGuide()` – byaruhaf Jan 16 '20 at 00:59
  • @byaruhaf I used your method and it ran but now I'm getting this error `Terminating app due to uncaught exception 'NSGenericException', reason: 'Unable to activate constraint with anchors and because they have no common ancestor. Does the constraint or its anchors reference items in different view hierarchies? That's illegal.` – allenhinson214 Jan 16 '20 at 01:08
  • 1
    Note section called Creating Layout Guides: https://developer.apple.com/documentation/uikit/uilayoutguide – Phillip Mills Jan 16 '20 at 01:49
  • @PhillipMills thank you for the link, it was great information to take in. – allenhinson214 Jan 16 '20 at 23:41

1 Answers1

1

Use: let layoutGuide = self.view.safeAreaLayoutGuide instead of var layoutGuide:UILayoutGuide.

al_mota
  • 431
  • 1
  • 4
  • 14