views:

34

answers:

1

The following code is from a NSTableViewDataSource where I'm trying to impliement drag and drop.

Can someone tell me why the setString:forTypes: method in the following code returns NO under Leopard? It works fine in Snow Leopard. I checked the "Pasteboard Programming Topics for Cocoa" legacy document but I can't figure out what I'm doing wrong.

- (BOOL)tableView:(NSTableView *)tableView writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *)pboard
{
    NSString *str;
    if ([tableView isEqualTo:databaseView]) {
        str = [[commander databases] objectAtIndex:[rowIndexes firstIndex]];
    } else if ([tableView isEqualTo:favouritesView]) {
        str = [[commander favourites] objectAtIndex:[rowIndexes firstIndex]];
    }

    if (str != nil) {
        NSArray *types = [NSArray arrayWithObject:NSStringPboardType];
        [pboard declareTypes:types owner:nil];
        if ([pboard setString:str forType:NSStringPboardType]) {
            return YES;
        } else {
            [self handleErrorString:[NSString stringWithFormat:@"Error: Couldn't copy '%@' to pasteboard!", str]];
        }
    }
    return NO;
}
A: 

This is a wild guess, but check the data: that pboard is not nil, and that str is really a string.

JWWalker
Wow, pboard *was* nil. But what would cause pboard to be nil?
Tim
Good question... maybe the pasteboard gets messed up somewhere else in your app that uses pasteboards? I don't know. Maybe you should have upvoted my answer but not accepted it.
JWWalker
I ran some tests with a relatively blank project and it looks like it's only nil when I use remote debugging. Maybe I should start a new question for this new actual cause of my problem.
Tim