views:

32

answers:

2

Hello everyone, 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 TextureBrowser *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.

A: 

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 ?

drkbrd
I just tried this, im getting an error:accessing unknown 'textureView' getter method
eemerge
Eugh - what about encapsulation?
JBRWilkinson
How would i use encapsulation?
eemerge
+1  A: 

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.

TechZen
Thanks, this almost did it, now the method in the View is called. I still have another problem though.Im loading the textures using NSFileManager, which returns an array with the files.Then in in a for cycle, im updating the textureList array with the values from the array returned earlier by NSFileManager.I do this by calling: [textureList addObject:....]The problem is at the end of the cycle, [textureList count] returns 0.Maybe there is a better way to copy the array returned from NSFileManager to my textureList array? And what am i doing wrong here that makes textureList have a 0 size?
eemerge
Found the problem myself, didnt alloc the array .Thanks again everyone for the help.
eemerge