I have UIView class that presents view that is created programaticly in a controller.
When creating (initing) the UIView I would like to transfer parameters from the UIViewController, so instance variables of the UIView can be initialized. I want it to happen before awakeFromNib
is called. So in awakeFromNib
I could use these parameters.
I guess I need to do it in - (id)initWithCoder:(NSCoder *)aDecoder
, but how? It only receives the aDecoder
Something like this:
- (id)initWithCoder:(NSCoder *)aDecoder {
if(self = [super initWithCoder:aDecoder]) {
_instanceParameter = parameterFromController;
}
return self;
}
-(void)awakeFromNib{
if (_instanceParameter)
do logic
}
From your question, at lot of things are a bit unclear. When you create your custom view, you can call a second init function. Something like this:
Then in your UIView class:
Just do all of the initialization you need to in the initWithParameter method.
I'm guessing you've subclassed "
UIView
" into something, let's call it "LudaView
".Expose a property for your parameters and when you load it from your xib file, you can set your parameters there. In other words:
You could also set a BOOL property or ivar within your "
LudaView
" and then when a drawing method is called for the first time, you can set stuff up. E.G.