0

I'm getting the Unable to simultaneously satisfy constraints error.

I don't get the error when the viewcontroller establishes itself using viewDidLoad but it does get the error when using loadView... Why is this happening?

I thought the only difference between loadView and viewDidLoad is that viewDidLoad occurs after loadView. At least, that seems to be the going explanation...

Sethypie
  • 549
  • 6
  • 21

1 Answers1

0

I don't know whether my answer would completely address your issue,but it might act as a starting point to resolve your issue.

There are quite a few points(you might be aware of) which needs to be noted before you use loadView:

  1. loadView is a method that gets called when view is loading,viewDidLoad is method that will be executed after the view is loaded.

  2. loadView is recommended when you are willing to create the view programatically instead of setting in xib file,other wise there is no point in using or calling loadView(It all depends on your application requirement though).

  3. Don't call super loadView if you initialise your view from story board or xib file.

  4. If you initialise your view from story board, do not call [super loadView] and you must assign your rootView to self.view property, if you call [super loadView] inside the method, you better never override this method and put your code in viewDidLoad method..

  5. If you are using xib file to set up the view,do the modifications of objects set up in viewDidLoad and don't call loadView,if you are creating the view programatically,initialise the view in the loadView and do the additional set up in viewDidLoad.

The constraint error generally pops up in story board or xib file,when "Use AutoLayout" is selected,if you unselect it,the error disappears,since you are creating the view programatically in loadView,it is your responsibility to see to it that the auto layout option is disabled i.e. you need to make use of setTranslatesAutoresizingMaskIntoConstraints property by setting it to "NO".

You can also refer to some of related questions here and there which could well get you out of this issue.

Thanks and happy coding :)

Community
  • 1
  • 1
Eshwar Chaitanya
  • 942
  • 2
  • 13
  • 34
  • Point 4 is totally incorrect, I call `[super loadView]` everywhere since 2010 and it didn't crash even once. – akashivskyy Aug 23 '13 at 22:37
  • @akashivskyy Thanks for pointing it,in a hurry I typed "when you create view programtically" instead of story board,edited the answer accordingly,cheers! – Eshwar Chaitanya Aug 27 '13 at 11:33
  • @akashivskyy But I would like to make a point here,if we use [super loadView] when creating view via story board,because the default view gets loaded from story board,if there is no xib,it creates an empty view,when we call loadView even after initialising view in story board,our program runs in to infinite loop,may be that 's something I failed to place(explain) properly in 4th point initially :) – Eshwar Chaitanya Aug 27 '13 at 11:42
  • That's why I don't play with this Storyboarding and XIB shit, I always create my views programmatically which gives me even more control over my hierarchy than IB visual interface. :D – akashivskyy Aug 27 '13 at 11:56