Re: Images in folder - simple question?
Re: Images in folder - simple question?
- Subject: Re: Images in folder - simple question?
- From: Jörn Salewski <email@hidden>
- Date: Wed, 28 Jan 2004 14:40:17 +0100
am 28.01.2004 12:41 Uhr schrieb Dominik Gwosdek unter email@hidden:
>
Hi,
>
>
I'm starting to learn cocoa and objective-c and I'm trying to write a
>
little app that has an NSImageView and only two buttons (back, forward)
>
and a folder with ca. 100 pictures(001.jpg ... 100.jpg). I have set up
>
an outlet to the ImageView and two actions for the buttons.Now I need a
>
little advice to implement the following action:
>
>
when the user clicks on for example on the forward button the
>
ImageView should display the next image from the folder(/images) and
>
so on.
>
>
I think I need to create an NSArray (with the content of a folder?).
>
>
>
- (IBAction)forwardButton:(id)sender
>
{
>
>
image = [NSImage imageNamed:@"001"];
>
[showImage setImage: image];
>
>
}
>
Looks like a good example App for a simple beginners tutorial. Mmh, maybe I
should consider writing my first tutorial...
Well, anyway, this is, what I think you should do:
1) Create an NSArray (maybe better an NSMutableArray) to store either
a) the images themself or
b) only the paths (or names) to the images as an NSString
2) keep track of the index of the currently displayed image
int currentIndex;
you could set currentIndex to -1 for the state that no image is
displayed.
3) In your action method something like (if you choose 1a):
currentIndex++;
NSImage *image = [imageArray objectAtIndex:currentIndex];
4) disable the next or previous button if there is no appropriate image to
display, e. g.:
[nextButton setEnabled: (currentIndex < [array count] - 1)];
If you have a lot of images or the images are very big and need fairly a
long time to instantiate, you could consider caching some of them. In this
case one would have two separate arrays, one containing the paths of all
images and a second containig some instantiated images. But this is getting
advanced.
Hope this helps you mastering Cocoa.
Cheers,
Joern Salewski
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.