subclassing and cocoa
subclassing and cocoa
- Subject: subclassing and cocoa
- From: Pejvan BEIGUI <email@hidden>
- Date: Sun, 20 Apr 2003 11:59:36 +0200
- Organization: Project:Omega
Hi all,
I really can't find what's wrong with my code, and I didn't find
anything helpful while digging out the list archives and google, so
after two days, here I am :-)
I've written a little subclass for dropping folders on an NSImageView,
and I wanted to extend it to add some more functionalities I need, but
I'm stuck because it seems that subclassing in cocoa is really
complicated, and must have a lot of catching to do about it...
Anyway, the problems I have are the following:
1) the folderPath string remains always "null"
2) calling the setImage: method of NSImageView class doesn't change the
image if I call it from another class. while it works from inside the class
For example, the following won't work:
testImageView = [[FFfolderWell alloc] init];
if (testImageView) {
NSLog(@"testImageView name and desc: %@ %@",[testImageView className],
[testImageView description]);
[testImageView setImage:[WS iconForFile:@"/Users"]];
}
and I don't understand why the [testImageView super] gives me an unknown
accessor error.
My biggest concern is that if I make a category for NSImageView and make
the pathString a global variable or an instance variable of another
class, all this code works fine.
Can anyone tell me what's wrong with this code and give me pointers or
some information about how to subclass?
Thanks a lot for any help,
Pejvan
#import <AppKit/NSImageView.h>
@interface FFfolderWell:NSImageView {
NSMutableString * folderPath;
}
+ (id)FFfolderWell;
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender;
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender;
@implementation FFfolderWell
+ (id) alloc
{
NSLog(@"FFfolderWell alloc");
self = [super alloc];
return self;
}
+ (id)FFfolderWell
{
return [[[self alloc] init] autorelease];
}
- (id) init
{
NSLog(@"FFfolderWell init");
if (self = [super init]) {
folderPath = [NSMutableString stringWithCapacity:64];
[folderPath retain];
return self;
}
- (void) dealloc
{
NSLog(@"FFfolderWell dealloc");
[folderPath release];
[super dealloc];
}
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{
NSPasteboard *pboard;
NSDragOperation sourceDragMask;
sourceDragMask = [sender draggingSourceOperationMask];
pboard = [sender draggingPasteboard];
if ( [[pboard types] containsObject:NSFilenamesPboardType] ) {
if (sourceDragMask & NSDragOperationCopy) {
return NSDragOperationCopy;
}
}
return NSDragOperationNone;
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender {
NSDragOperation sourceDragMask;
NSPasteboard *pboard;
BOOL isDir;
// [self bordel];
sourceDragMask = [sender draggingSourceOperationMask];
pboard = [sender draggingPasteboard];
if ( [[pboard types] containsObject:NSFilenamesPboardType] ) {
NSArray *files = [pboard propertyListForType:NSFilenamesPboardType];
NSWorkspace * WS = [[NSWorkspace sharedWorkspace] retain];
NSString *firstFolder = [NSString stringWithString:[files
objectAtIndex:0]];
if ([[NSFileManager defaultManager] fileExistsAtPath:firstFolder
isDirectory:&isDir] && isDir) {
[self setImage:[WS iconForFile:firstFolder]];
//NSLog(@"setting folderPath: %@
(firstFolder:%@)",folderPath, firstFolder);
return YES;
}
}
//never reached
return NO;
}
//not used yet
/*
- (void) concludeDragOperation:(id <NSDraggingInfo>)sender
{
NSLog(@"concludeDragOperation");
}
*/
- (NSString *) folderPath
{
NSLog(@"FFfolderWell folderPath: %@",folderPath);
return folderPath;
}
- (void) setFolderPath:(NSString *)newPath
{
NSLog(@"newPath: %@", newPath);
[folderPath setString:newPath];
NSLog(@"newFolderPath: %@", folderPath);
}
@end
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.