views:

26

answers:

1

Hello,

The title question might be a little vague. I will try to explain as good as i can (also note im new to cocoa programming so excuse any mistakes :) ).

I have a VIEW that extends NSView where i would like to draw some images. I want the images to be loaded from some files on the disk, when i click a button.

I managed to do all the loading into an NSMutableArray. My problem is, how to setup things: - i need the NSMutableArray with the images (paths) to be available for the loading function (so i put it in a controller and assigned an action to the button in the UI). but in this case, how can i acces it in the drawRect function of my custom view class?

  • if i put it as a member of my custom view class, i dont know how to link it to the button , so that on the button click , the array will be filled with images paths.

I guess im a bit confused since im new to osx programming , on how these things get connected.

Hope someone could clear the air a little for me . Thanks.

A: 

The images view should have a property to hold an array of images, and the controller should set this property to its array of images. (The images view should, of course, make its own shallow copy of the array.)

images (paths)

Assuming you mean pathnames, images are not paths, and paths are not images. The controller should load the images and pass the images off to the view. The view should not care where the images might have come from.

Peter Hosey
Thanks for the infos, and yes, pathnames is what i mean ( more exactly i just read files from a folder and store them in the array).But how do I pass the images from the controller to the view?Lets say i have:@interface MyView : NSView {NSMutableArray *images;...}...@endand a controller:@interface MyController : NSOBject {NSMutableArray *imagesInController;}@endhow do i set the images array from the controller?
eemerge
As I said, the view should have a property. The controller would simply send the view a message to set that property. See the Objective-C Programming Language document: http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocProperties.html
Peter Hosey