views:

48

answers:

2

i create a c array in the firstClass (this is created in the interface):

BOOL        taken[25];

i then go to a different view and come back to the first one, except my c array is reset to 0,

how do i retain my array when i go back an forth between views?

+2  A: 

You cannot send retain messages to plain C arrays. Normal C memory management applies. I.e. local stack variables will fade away when out of scope, global variables will live, etc. Use dynamically allocated memory (malloc or new in C++) if you need "long-living" memory, but you are responsible to free it when you're done with it.

Eiko
thank you both for the information, i now know what i need to dothanks again :)
Ryan Erb
+1  A: 

The lifetime of an immediate array like "BOOL taken[25]" is the same as the lifetime of the object that it is in. If the surrounding object gets deallocated the array goes with it; conversely, if the surrounding object is retained then so is the array. So to keep this array around, make sure the view is not deallocated, and make sure it's the same view object as you used last time.

In terms of iOS view control in particular (which is I think what you're asking about), try to write your business logic in your "view controller", and have it re-use UIView objects. Or, if you don't re-use the same view, at least have it initialize the new view (including the array) to the correct value.

samkass