in the .h file:
double var1;
NSString *Items[90];
in the .m file:
var1 = 1000;
NSString *j = [NSString stringWithFormat:@"%g", var1 ];
Items[42] = [@" Per each " stringByAppendingString: j ];
see code above, the issue is that thru the app running i have a proc that needs this
Items[42] value however the value is not there anymore ( i didn’t erase it ) but
the cell is completely empty no null or spaces, as if the cell value was released.
on the other hand if i just place in Items[42] some string with no attached variable (like var1) (i.e. Items[42] = @”hello there”; )
then all is ok and the value of Items[42] is being preserved.
any idea why the cell when presented with a variable content (like var1 ) the cell lose content?
TIA
The reference counter of temporary string is zero. It would be destroyed at any time. There are three options to solve the problem:
Items[42] = [[@" Per each " stringByAppendingString: var1 ] retain];In non-ARC env, and remember to call
[Items[42] release]later.NSMutableArray*orNSArray*, i.e.NSMutableArray*Items. Which will automatically manage the reference count of its
objects
For global (static) constant strings, they have an infinite reference counter, and would never be destroyed.