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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-16-2009, 07:57 PM   #1 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 3
Default Using NSArray as an array of images and load one at a time.

I have an NSArray that loads 30 images when the viewloads up.

I have a UIImageView that can display only one of these images at a given time.

The user clicks on a button to see the next image.

On each click I am doing this :
--
UIImage *img = [imageArray objectAtIndex:current_img_number];
[img_view setImage:img];
--

However the app crashes on every click.

Can anyone help me please?

Thanks,
Paris.
paris is offline   Reply With Quote
Old 07-17-2009, 02:46 PM   #2 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 3
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
Old 09-18-2009, 01:37 AM   #3 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 28
Default I'm doing something similar but having a counter problem

Quote:
Originally Posted by paris View Post
I have an NSArray that loads 30 images when the viewloads up.

I have a UIImageView that can display only one of these images at a given time.

The user clicks on a button to see the next image.

On each click I am doing this :
--
UIImage *img = [imageArray objectAtIndex:current_img_number];
[img_view setImage:img];
--

However the app crashes on every click.

Can anyone help me please?

Thanks,
Paris.
Paris - I am putting together a similar application. The counter I am using (analogous to your 'current_img_number' variable), is causing my program to crash whenever I increment it. Can you tell me how your are defining your counter and how you are incrementing it? When I initially set it, everything works. It's only after I come around a second time and increment it that the program crashes. I am getting a objc_msgSend error.

Thanks for you help.

Kyle
KyleTomson is offline   Reply With Quote
Old 09-18-2009, 02:44 AM   #4 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 536
Default

Kyle, how are you defining and incrementing your counter? If you post that code, someone can help you fix it.
eddietr is offline   Reply With Quote
Old 09-18-2009, 03:20 AM   #5 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 6
Default

Quote:
Originally Posted by eddietr View Post
Kyle, how are you defining and incrementing your counter? If you post that code, someone can help you fix it.
NSArray *arrTemp = [[NSArray alloc]initWithObjects:@"1.jpg",@"2.jpg",nil];
arrayQuotes = [[NSMutableArray alloc]initWithArray:arrTemp];


use the mutable array and index no
SnehaSingh is offline   Reply With Quote
Reply

Bookmarks

Tags
array, crash, image, nsarray, uiimageview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 250
20 members and 230 guests
ADY, bookesp, ckgni, dacapo, Dani77, DarkAn, Davey555, Desert Diva, HemiMG, iDifferent, jakerocheleau, JasonR, LEARN2MAKE, prchn4christ, Rudy, ryantcb, Speed, themathminister, theone8one
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,766
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:40 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0