开发者

NSPasteboard setString:forType: returns NO under Leopard, fine in Snow Leopard

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 wr开发者_高级运维ong.

- (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;
}


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜