开发者

Cocoa: how to connect a button to a view?

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 ne开发者_高级运维ed 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜