IKImageBrowserView moveItemsAtIndexes and imageRepresentationType
IKImageBrowserView moveItemsAtIndexes and imageRepresentationType
- Subject: IKImageBrowserView moveItemsAtIndexes and imageRepresentationType
- From: Greg Wilson <email@hidden>
- Date: Sun, 13 Feb 2011 17:57:43 -0500
I have an App which uses IKImageBrowserView and wanted to implement moveItemsAtIndexes. I added the necessary protocol routine
- (BOOL) imageBrowser:(IKImageBrowserView *) view moveItemsAtIndexes: (NSIndexSet *)indexes toIndex:(NSUInteger)destinationIndex
{
NSLog(@"moving items");
return YES;
}
just to see if it would get called. To my surprise, it didn't. After much grinding of teeth and pulling of hair I determined that I could get the above to be called if I changed the imageRepresentationType returned by myImage objects to return IKImageBrowserPathRepresentationType objects instead of IKImageBrowserNSDataRepresentationType. ie I commented out the lines indicated and returned IKImageBrowserPathRepresentationType info :
/* let the image browser knows we use a path representation */
- (NSString *) imageRepresentationType
{
//return IKImageBrowserNSDataRepresentationType;
return IKImageBrowserPathRepresentationType;
}
/* give our representation to the image browser */
- (id) imageRepresentation
{
//return _data;
return [self localFilePath];
}
To be clear, the program worked fine, it displayed images, resized them, scrolled etc. However, the moveItemsAtIndexes procedure would not get called. it certainly seemed like all functionality except reordering is supported for IKImageBrowserNSDataRepresentationType.
I am at a loss to explain why and wonder if it is a bug? I certainly can't find anything in the documentation which suggests that you can only reorder items which are IKImageImageBrowserPathRepresentationType.
To make sure something else wasn't causing this I downloaded the Apple examples ImageBrowser and ImageBrowserViewAppearance and made minor changes to use the IKImageBrowserNSDataRepresentationType instead of the IKImageImageBrowserPathRepresentationType they used. This was relatively simple, I just changed the myImageObject to store the NSData
@interface myImageObject : NSObject
{
NSString* path;
NSData *data; // also store NSData for the object
NSImage *theImage; // also store NSImage for the object
}
added setters for the new fields
- (void) setData:(NSData *) theNewData
{
if(data != theNewData){
[data release];
data = [theNewData retain];
}
}
- (void) setImage:(NSData *) theNewImage
{
if(theImage != theNewImage){
[theImage release];
theImage = [theNewImage retain];
}
}
returned it as the represented data to the browser
- (NSString*)imageRepresentationType
{
//return IKImageBrowserPathRepresentationType;
//return IKImageBrowserNSImageRepresentationType;
return IKImageBrowserNSDataRepresentationType;
}
- (id)imageRepresentation
{
//return path;
//return theImage;
return data;
}
And added the data when the myImageObject was created, ie after
myImageObject* p = [[myImageObject alloc] init];
[p setPath:path];
add the following
NSURL *imageUrl = [NSURL fileURLWithPath:path];
NSData *theData = [[NSData alloc] initWithContentsOfURL:imageUrl];
NSImage *thisImage = [[NSImage alloc]initWithData:theData];
[p setImage:thisImage];
[p setData:theData];
Both programs continue to display the browser and images properly except they no longer call moveItemsAtIndexes and didn't allow reordering. When you click and try to drag the image, nothing happens. The same is true if you modify the above to use IKImageBrowserNSImageRepresentationType.
Anyone else experience this? Anyone have an explanation?
TIA
-greg
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden