Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Draw This
($0.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 07-17-2009, 01:46 PM   #2 (permalink)
paris
Registered Member
 
Join Date: Jul 2009
Posts: 3
paris is on a distinguished road
Default Solved.

If you want to retain the elements in an NSArray across functions then you have to pass it the retain message.

1. So in Header file I have :
NSArray *imageArray;

2. In Implementation I have this inside "viewDidLoad()"

imageArray = [[NSArray arrayWithObjects:
[UIImage imageNamed:@"01.JPG"],
[UIImage imageNamed:@"02.JPG"],
[UIImage imageNamed:@"03.JPG"],
[UIImage imageNamed:@"04.JPG"],
nil] retain];

3. notice the retain message that gets passed to NSArray. This makes sure the objects are persistent in memory and available when "imageArray" is accessed in other functions.

4. without the retain message, the objects are released in viewDidLoad() and trying to access the array elements in another function will result in a crash.
paris is offline   Reply With Quote
 

» Advertisements
» Online Users: 573
12 members and 561 guests
blasterbr, Domele, Dump3, esoteric, GarryTheGarlic, iekei, ITCreative, nt.hai, OgreSwamp, OneGoodApp, Penicillin, tranvutuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 174,548
Threads: 93,727
Posts: 401,266
Top Poster: BrianSlick (7,954)
Welcome to our newest member, rosalvadx91
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:24 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.