I'm trying to do some fanciness with XIBs and that includes wanting to somehow get and store the paths of images loaded from the xib. To do this, I made some categories and did some method swizzling to override all the UIImage constructors to save their path before calling their parent constructor.
But due to Apple's black box BS with all their XIB stuff, absolutely none of the exposed constructors for UIImage seem to get called when I create a UIImageView through [UIViewController initWithNib...].
Does anybody know what function call happens or how they do this? I can't find any information whatsoever that exposes what initWithNib actually does behind the scenes.
EDIT: If you're in a similar situation, you may try using the accessibilityLabel / accessibilityHint which is automatically populated with the image path. The only issue is that accessibility needs to be enabled or these values are nil.
UIImageViewand set the objects in the XIB to be your new
EliImageViewobjects and then you can do all sorts of crazy things - Michael Dautermann 2012-04-03 22:48
I know the objects constructed from a Nib are being unarchived according to the NSCoding protocol; you need to override
initWithCoder: in this case.
You could use swizzling to replace UIImageView's
initWithCoder: method, then snoop around to see if an image name or path is available in any of the coder's keys. This might be more effective than hacking UIImage itself, since for all we know UIImageView could be using a custom subclass that you don't have access to.
initWith... methods are meant for programatically creating
Sounds like you want to catch things as they are instantiated from XIB files. That would be the parent class
UIView documentation says:
initWithCoder: - Implement this method if you load your view from an Interface Builder nib file and your view requires custom initialization.
You are both close to right - I tried doing this with
UIImageView which works for
initWithCoder as you guys are both suggesting. However, UIImage doesn't get
initWithCoder called for some reason, instead it uses
initWithCGImageStored:(CGImageRef)cgImage scale:(CGFloat)scale orientation:(UIImageOrientation)orientation.
If and when I actually get the path out of this as I desire I'll post it up here. Thanks for the help, gents.