Cocoa:如何将按钮连接到视图?
标题问题可能有点模糊。我会尽力解释(另请注意,我是可可编程的新手,所以请原谅任何错误:))。
我有一个扩展 NSView 的 VIEW,我想在其中绘制一些图像。 当我单击按钮时,我希望从磁盘上的某些文件加载图像。
我设法将所有加载到 NSMutableArray 中。我的问题是,如何设置: - 我需要带有图像(路径)的 NSMutableArray 可用于加载功能(因此我将其放入控制器中并为 UI 中的按钮分配了一个操作)。但在这种情况下,我如何在自定义视图类的drawRect函数中访问它?
- 如果我将其作为自定义视图类的成员,我不知道如何将其链接到按钮,以便在单击按钮时,数组将填充图像路径。
我想我有点困惑,因为我是 osx 编程新手,不知道这些东西是如何连接的。
希望有人能为我澄清一下。谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
图像视图应该有一个属性来保存图像数组,并且控制器应该将此属性设置为其图像数组。 (当然,图像视图应该创建自己的数组浅表副本。)
假设您指的是路径名,图像不是路径,路径也不是图像。控制器应该加载图像并将图像传递到视图。视图不应该关心图像可能来自哪里。
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.)
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.