2
- (BOOL) imageBrowser:(IKImageBrowserView *) aBrowser moveItemsAtIndexes: (NSIndexSet *)indexes toIndex:(NSUInteger)destinationIndex;

This datasource method for reordering in IKImageBrowserView is not being called. Nib connections have been made correctly. setAllowsReorderdering is set YES.

But it isn't working yet.

- (void)imageBrowser:(IKImageBrowserView *)aBrowser removeItemsAtIndexes:(NSIndexSet *)indexes

At the same time, the above method for deleting items is correctly called and works perfectly. Why not for reordering ?

When I drag the item to reorder, the following drag and drop code is being called. There are actually 2 IKImageBrowserViews here.

- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{           
NSPoint draggingLocation = [self convertPoint:[sender draggingLocation] fromView:nil];
NSRect contentRect  = [[_indexContentBrowserView enclosingScrollView] frame];
BOOL isForContent   = (contentRect.origin.x < draggingLocation.x) && (draggingLocation.x < contentRect.origin.x + contentRect.size.width);

if (isForContent)
{
    if ([sender draggingSource] == _indexContentBrowserView)
    {
        return NSDragOperationMove;
    }
    else
    {
        NSPasteboard *pb = [sender draggingPasteboard]; 
        NSString * type = [pb availableTypeFromArray:[NSArray arrayWithObject:NSFilenamesPboardType]];

        if(type != nil)
        {
            return NSDragOperationEvery;
        }           
    }
}
else
{
    if ([sender draggingSource] == _indexListBrowserView)
    {
        return NSDragOperationMove;
    }
    else
    {
        NSPasteboard *pb = [sender draggingPasteboard]; 
        NSString * type = [pb availableTypeFromArray:[NSArray arrayWithObject:NSFilenamesPboardType]];

        if(type != nil)
        {
            return NSDragOperationEvery;
        }           
    }
}

return NSDragOperationNone;



}
Soorya
  • 39
  • 5
  • Welcome to SO. Please write and format carefully your code and try to give all the information needed to understand the problem. This will yield to you more chances of getting valuable answers – joaquin Nov 20 '11 at 11:25
  • Thank you Joaquin. Sure. I will. – Soorya Nov 20 '11 at 11:32
  • Have you tried commenting out your custom drag/drop code? Perhaps the `moveItems` function isn't getting called because you're overriding default behavior. – Dov Nov 28 '11 at 17:30
  • @Dov: Thank you. Exactly. The function was being overridden. Thanks a lot. But, how do i overcome this problem? I need the drag/drop code. One solution is that i can implement reordering code in *draggingEntered* method itself where i find it hard to get the destination indexes. Any different ways? – Soorya Dec 01 '11 at 10:34

2 Answers2

1
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
{
    [super prepareForDragOperation:sender];

    if(nil == [sender draggingSource])
        return YES;

    BOOL success = NO;

    if (_galleryMultiImageFileBrowserView != [sender draggingSource])
    {
        //Code for checking the duplication of files
    }
    else
    {
        success = YES;
    }
    return success;
    //I had returned NO here which was the reason for the problem.
}

I found out the problem. It was my mistake. The above code is the corrected one. Earlier, when the [sender draggingSource] was the IKImageBrowserView, it returned NO. That was the reason why the moveItemsAtIndexes: method was not being called.

@Dov: Thank you Dov for giving your precious time. Thanks a lot. @Joaquin: Thank you very much.

Soorya
  • 39
  • 5
  • You didn't show `-prepareForDragOperation:` before. What was broken in it? Also, you should accept your answer. – Dov Dec 05 '11 at 15:45
  • @Dov: Nothing was broken as such. I had to just return YES instead of NO in the above datasource method. Returning NO will not call the 'moveItemsAtIndexes:' method. – Soorya Dec 28 '11 at 11:24
  • Oh, alright. Still, I recommend you accept your answer. That makes it the top answer, so that people who have a similar issue can tell that it was the answer you marked as correct. – Dov Dec 28 '11 at 13:18
  • You click the big check mark to the left of this answer. It'll turn green. You can also vote on the usefulness of questions and answers on this site too, but using the arrows above and below each vote count. – Dov Dec 29 '11 at 13:41
0

Based on your comments, your problem seems to be that you've overridden the built-in drag/drop functionality, and so you no longer get reordering "for free". I would recommend calling the super implementation at the beginning of your override, like so:

[super draggingEntered:sender];

That might not work for you, but if not, I'm not sure what would. You say you do need the drag/drop code - two questions along those lines: first, what do you hope to achieve? Second, is overriding draggingEntered: the best/only way to achieve this?

Dov
  • 15,530
  • 13
  • 76
  • 177
  • Drop is already done. What i exactly need is this - To implement reordering in the *draggingEntered:* method, i have to get the destination indexes to update the mutable array. How do i get it/them? – Soorya Dec 01 '11 at 13:25
  • Did you try calling `super`, as I suggested above? – Dov Dec 01 '11 at 13:59
  • I did try. But the problem was not that as I have answered below. Thank you very much. – Soorya Dec 02 '11 at 08:05