iOS w/ storyboards & ARC: Controller property not initialized

Go To StackoverFlow.com

0

The problem is simple to explain but difficult for me to resolve. I have a property that is NEVER initialized.

First of all, I'm using the iCarousel custom class in order to display some images for my app. In one of its delegate methods (the one that it uses in order to know which view is going to show at some index), I use this code:

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
   if(!view)
   {
      CustomController* controller = [self.storyboard instantiateViewControllerWithIdentifier: "identifier"]; 
      //BTW, the CustomController is initialized properly. Its instance is not nil after the initialization.
      controller.imageView.image = [UIImage imageNamed: "something.png"];
      view = controller.view;
   }

   return view;       
}

As you can see, the view that I show in my carousel is a custom view with its own controller. I initialize it using the storyboard method and then I just set the image in my imageView property, which is, obviously, an UIImageView.

Don't get excited and say that I'm not initializing my imageView, because I have a custom getter in my "CustomController" class. Like this:

//interface (.h)

...

@property (nonatomic, strong) UIImageView* imageView;

...

//implementation (.m)

...

@synthesize imageView = _imageView;

...

- (UIImageView*) imageView
{
   if(!_imageView)
      _imageView = [[UIImageView alloc] init];
   return _imageView;
}

...

Believe it or not, even if I put a breakpoint in the "_imageView = [[UIImageVIew alloc] init];"... the program executes that line but the _imageView remains nil. ¿Why?

I don't want to know "How to set my property", so please don't give workarounds for this... what I want to know is "Why my property is never setted and remains nil always", what's am I doing wrong?.

I've also tried to use my imageView as an IBOutlet... but even if I link it to an imageView in the Interface Builder and check its value after the "viewDidLoad", it still remains nil.

P.S: Btw, I'm using ARC (yeah, I know is in the title... xD)

2012-04-03 21:56
by Alex Takashi Tanabe
Did you verify that your CustomController is not nil after storyboard instantiation - Brian Palma 2012-04-03 22:00
Yep, my CustomController is not nil. I forgot to mention that too - Alex Takashi Tanabe 2012-04-03 22:00
Are you able to post the exact code - Brian Palma 2012-04-03 22:02
I may post the exact code for the initialization of my controller and the name of the delegate method of the iCarousel, but nothing else coz is irrelevant. As you can see, the problem is within that method, the imageView should be initialized after i set its property - Alex Takashi Tanabe 2012-04-03 22:07
You should also read up on iCarousel and Storyboards + ARC...seems to be some issues using that particular class - Brian Palma 2012-04-03 22:10
Probably, but what about the instance of my own class. It doesn't depend on the iCarousel, so why can't they be initialized? = - Alex Takashi Tanabe 2012-04-03 22:12
BTW... from the iCarousel Documentation:

ARC Compatibility

"ARC Compatibility

As of version 1.6.1, iCarousel automatically works with both ARC and non-ARC projects through conditional compilation. There is no need to exclude iCarousel files from the ARC validation process, or to convert iCarousel using the ARC conversion tool. - Alex Takashi Tanabe 2012-04-03 22:14

Are you using LLDB? It often gives me nil values incorrectly.. - borrrden 2012-04-03 23:43
I think I am... how do I turn it off then? o.O However, is that really a problem - Alex Takashi Tanabe 2012-04-05 04:32


0

Well, it looks like the answer was what borrrden said, the problem was the LLDB debugger. Actually, my property was initialized but the debugger didn't detect it like that, if I change it to GDB I could see it wasn't nil after all. Furthermore, the reason why I had also issues with my child viewcontroller's outlets was because I didn't use the View Controller Container methods in iOS5 (DidMoveParentViewController and those ones).

Kinda tricky.

2012-04-11 16:26
by Alex Takashi Tanabe