Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XCode 6 - iOS 8: programmatically check if view is installed

I am using class sizes in interface builder, defining slightly different designs for different sizes.

One of my view is not installed for a specific size. That works as expected, but now I would like to programmatically be able to tell if that view is installed or not. Whether it is installed or not, it looks like the view is never nil, and I can't see any isInstalled flag to check.

What is the correct way to do this?

like image 702
JP Hribovsek Avatar asked Oct 17 '14 03:10

JP Hribovsek


1 Answers

This isn't a great solution, but I've not found a better one yet:

The docs state that "A runtime object for an uninstalled view is still created. However, the view and any related constraints are not added to the view hierarchy and the view has a superview property of nil".

So a test for a valid superview works as a solution, but I've found that it has to come quite late - in viewDidAppear. The superviews are still nil in viewWillAppear, for example.

like image 61
nmw Avatar answered Nov 07 '22 04:11

nmw