My ViewController creates 60 little UIViews. Each one requires a UIImage of the same jpg (to use in a UIImageView).
My theory is that instead of each UIView creating its own UIImage, it would be better to reuse one UIImage, defined in the ViewController.
ViewController code:
UIImage *reuseableUIImage = [UIImage imageNamed:@"LittlePicture.jpg"];
for (i=0; i<60; i++){
[arrayOfUIViews addObject:[[myUIViewMaker alloc] init...]];
}
Is my theory wrong? Should I just go ahead and create the UIImage in each UIView?
If my theory is good, how can my UIViews target the parent ViewController’s UIImage?
I don’t know the syntax. To illustrate (badly), the code inside the UIView would be something like this:
finalUIImageView = [[UIImageView alloc] initWithImage:self.parentViewController.reuseableUIImage];
Your code looks ok and should work correctly. You would need to define a property on your viewController to hold the UIImage.
The main benefit you will get from this is that the time to load the image will only happen once. If you alloc and init an image for each view it will have to load the image each time.
EDIT:
Thinking about it again, the best way would be to pass the image into your child view when you init it.
Your init method in your myUIViewMaker class would be implemented as: