0
votes

Due to designer for an app I'm working on, I have to cram a lot of things into one view controller. I figured I would lessen some CPU strain and save some time by skipping on calling

[super layoutSubviews];

on hidden views (and be views I mean a subclass of UIView that holds all other stuff) and only refresh it before view is going to appear. If it matters to some of you, I do this by setting BOOL flag. This works fine on iOS8 but crashes app on iOS7 with:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Auto Layout still required after executing -layoutSubviews. XXX's implementation of -layoutSubviews needs to call super.'

So how can I skip calling layoutSubviews on iOS7?

Of course, there is this possibility that I completely don't understand how iOS works and skipping this call doesn't save any time because it calculates constraints anyway. In that case, the question would be 'how can I skip calculating constraints for hidden views?'.

1

1 Answers

0
votes

If you were dropping iOS 7 support, iOS 8 adds the ability to disable and enable constraints via the active property. But If you need to support iOS 7, your only option is to remove the views and/or constraints from the view hierarchy, and reinstate them when you need them again.

But are you sure that -layoutSubviews is causing a slowdown? You should run something like the Time Profiler in Instruments to make sure that really is the problem, before trying to optimize it.