I have a class I wrote called Location that just holds some strings. I'm using two instances of that class in a view controller, and when I initialize the two variables in viewDidLoad, they work fine for that method, but then when I try to use them later they are null. I have them set as retained properties. I have tested them and know that they are initialized for viewDidLoad (I use their fields in the view). Do I have to do something special in the Location class to make sure they don't get released? When I re-initialize them in a different method, everything runs smoothly.
views:
71answers:
3You can post comments on your questions and answers to your questions, even with 1 reputation; there's an "add comment" button under the question comments, just before the answers start
Michael Mrozek
2010-08-06 02:20:35
yeah it's not there. not sure why. but i was wrong it doesn't work.
marty
2010-08-06 02:32:40
+1
A:
Instance variables properly initialized in viewDidLoad should retain values normally just like they would in any other method. A coding error may cause the issue you are describing, e.g. if you have local variables in viewDidLoad hiding identically named instance variables.
Roman K
2010-08-06 02:21:46
A:
you (or the event loop) is probably releasing the objects you are initializing after viewDidLoad is complete since they are autoreleased or something. To prevent that, make the variables in question properties on the class with the "retain" attribute and set them to nil on dealloc.
Cappuccino Plus Plus
2010-08-06 05:57:21