开发者

Cocoa - calling a VIEW method from the CONTROLLER

Got a little problem i asked about it before but maybe i didnt ask properly. I have a cocoa application, which amongst other things, must do the following task: - load some images from the disk, store them in an array and display them in a custom view.

In the Interface Builder i have a CustomView and an OBJECT that points to TexturesController.h

The custom view is a custom class, TextureBrowser. Below is the code for the controller and view:

TexturesController

#import <Cocoa/Cocoa.h>

@class TextureBrowser;

@interface TexturesController : NSObject {  
  IBOutlet NSTextField *logWindow;  
  IBOutlet TextureBr开发者_运维知识库owser *textureView;
  NSMutableArray *textureList; 
} 
@property textureView;
-(IBAction)loadTextures:(id)sender;
-(IBAction)showTexturesInfo:(id)sender;
@end

TextureBrowser

@interface TextureBrowser : NSView {
  NSMutableArray *textures;
}
@property NSMutableArray *textures;
-(void)loadTextureList:(NSMutableArray *)source;
@end

These are just the headers. Now , what i need to do is:

  • when loadTextures from the TexturesController is called, after i load the images i want to send this data to the view (TextureBrowser), for example, store it in the NSMutableArray *textures.

I tried using the -(void)loadTextureList:(NSMutableArray*)source method from the view, but in the TextureController.m i get a warning : No -loadTextureList method found

This is how i call the method :

[textureView loadTextureList: textureList];

And even if i run it with the warning left there, the array in the view class doesnt get initialised.

Maybe im missing something...maybe someone can give a simple example of what i need to do and how to do it (code).

Thanks in advance.


In TexturesController.m, you have to import TextureBrowser.h so that the controller knows what methods the property textureView has. Right now, you've just got a blank placeholder symbol instead of an actual class.

Since textureView is defined by an outlet, you need to make sure that its class is properly set in Interface Builder. If you provide a generic NSView instead, it won't have the loadTextureList: method.


If you imported TextureBrowser.h in TexturesController.m, I don't see why it wouldn't find your method.

But why don't you simply call self.textureView.textures = textureList; from the TexturesController ?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜