gpt4 book ai didi

objective-c - 从 NSTableView 拖放到 NSImageView

转载 作者:行者123 更新时间:2023-12-03 17:00:44 27 4
gpt4 key购买 nike

我需要从 NSTableView 中拖动一行包含图像路径并将其放在 NSImageView 上,并且拖动行的图像应该出现在 imageview 中。感谢帮助

最佳答案

非常感谢。确实有效。我为 NSStringPboardType 和 NSFilenamesPboardType 注册了 NSImageView 和 NSTableView。然后在 TableView 委托(delegate)中我使用了以下代码。

- (BOOL)tableView:(NSTableView *)tv writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard*)pboard
{
NSString *string = [filePath objectAtIndex:[rowIndexes firstIndex]];
[pboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:self];
[pboard setString:string forType:NSStringPboardType];
return YES;
}

并且在 NSImageView NSDragging Destination 非正式协议(protocol)中,使用了以下代码。

- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{
NSString *str = [[sender draggingPasteboard] stringForType:NSStringPboardType];
myImage = [[NSImage alloc] initWithContentsOfFile:str];
[self setImage:myImage];
[self setNeedsDisplay: YES];
return NSDragOperationCopy;
}

干杯:)

关于objective-c - 从 NSTableView 拖放到 NSImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1057112/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com