This recent question got me thinking about category conflicts, specifically involving the UIViewControllerRotation
category within UIViewController.h
. This category includes the shouldAutorotateToInterfaceOrientation:
. If one wanted to override this method (via a category) and make it run the same code for every UIViewController
(as the linked post is trying to accomplish) then they'd have two categories with the same method - something that I read leads to undefined behavior.
I gave this a try and, for a standard view-based application in iOS 4.3, the rotation logic fell back to the default, portrait only rotation, effectively ignoring the category. This was with no shouldAutorotateToInterfaceOrientation:
method defined in my UIViewController
subclass. Interestingly, when I did define the shouldAutorotateToInterfaceOrientation:
method and simply called return [super shouldAutorotateToInterfaceOrientation:]
then the category was called. So this leaves me with two question:
Any feedback is much appreciated! Thanks.
Suggestion; don't do that!!!
You really don't want to override behavior of all instances of any given UIKit class across all instances within your application for a couple of reasons.
First, you'll be changing the behavior of the class in ways that the class was likely not designed to deal with. As well, instances that are in UI hierarchies that are beyond your control (embedded complex framework components, typically) will behave differently, too.
Secondly, there is no way your implementation can know the internal implementation details of the original implementation to the point of not risking failing to make the same assumptions. While you could do something swizzle-like, down that path is extremely fragile and will be a maintenance nightmare.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With