-
Notifications
You must be signed in to change notification settings - Fork 121
Update on Injection
##Description This page is answer on question "Why, even if I see that my controller changes, I dont' see any changes on screen?"
##Update on class injection
Sometimes, default code injection doesn't allow you to correctly update objects that was already created.
It happens because they already passed "initialization phase", i.e. view was already loaded to ViewController, controller had already called initWithNibName:
method.
In this case, you need to implement -(void)updateOnClassInjection
in class, that you're going to inject.
This method will be called on each class injection on all instances of this class, and instances of this class subclasses.
For example, in dyci example project, you could see this kind of code:
- (void)viewDidLoad {
[super viewDidLoad];
[self createGUI];
}
- (void)updateOnClassInjection {
// "Emulating" viewDidLoad method
// Cleaning up all views and
NSArray * subviews = [[self view] subviews];
for (UIView * v in subviews) {
[v removeFromSuperview];
}
[self createGUI];
}
Note, that -(void)updateOnClassInjection
is optional method. You do not need to place it in each class you want ot be updated. But in case, if you need to "reconfigure" your class, or "emulate" recreation - use it :) There's some thoughts about what you should and what you shouldn't write in -(void)updateOnInjectionClass
method.
Also, we have some examples, that will help you to understand what code you should wrtie in these methods.
##Update on resource injection
Dyci allows you not only to inject code. But, to inject resources also.
At current moment you can inject only .png and .jpg files.
So, in case if you need to peform some additional logic on resources injection (flush buffers, re-read data), you just need to override next method
- (void)updateOnResourceInjection:(NSString *)resourcePath