I want to use iCarousel ( a library providing a coverflow scrolling style )
I have created a View with XIB. On that View I have UIImageView
And I have a Controller for that View with all the IB things set up ( ‘view’ of the FileOwner set to my view and there is an outlet of UIImageview )
Programmatically I create the Controller
SBTViewController* iv1 = [[SBTViewController alloc] initWithNibName:@"SBTViewController_iPhone" bundle:nil];
SBTViewController* iv2 = [[SBTViewController alloc] initWithNibName:@"SBTViewController_iPhone" bundle:nil];
and then
UIImage* im1 = [UIImage imageNamed:@"1.png"];
iv1.imView.image = im1;
UIImage* im2 = [UIImage imageNamed:@"2.png"];
iv2.imView.image = im2;
Please note that I am not adding the view of iv1 controller to be shown or be part of any hierarchy just now.
Instead, I am storing the pointer, and some time later ( when the carousel moves ) I simply give the iv1.view to the carousel to show it up.
I can see the view but not the image …
After searches I found a question on stackoverflow where it is explained that setting image to the imageview before it was added to the views hierarchy will not actually work, meaning that I can only set up images programatticaly after ViewDidLoad.
But in my case I want to init each instance with different values, so adding code in in ViewDidLoad is not robust enough …
Edit : I just found out that simply accessing the view paramater of the controller like this
iv1.view.tag
will cause the view to be loaded
So How should I do it ?
Hide it beneath others ? Ugly
thanks
Your problem is that when you create your UIImage, your UIImageView is not yet created. So two solutions: you create your UIImage after the viewDidLoad. But if you don”t want that, you may remove your UIImageViews from your XIB and create them yourself in the init method of your class, and then add them to your view hierarchy in the viewDidLoad.