gpt4 book ai didi

objective-c - 拖入 nscollectionview 崩溃

转载 作者:搜寻专家 更新时间:2023-10-30 20:08:27 24 4
gpt4 key购买 nike

我有一个 NSCollectionView 显示内部存储的图像(即不是文件)。集合显示正确。但是,当我开始拖动操作时,应用程序崩溃了。它在拖动离开 Collection View 之前崩溃。我正在返回拖动图像的内部图像。崩溃日志显示崩溃发生在拖动代码中。我一定是遗漏了什么,但我找不到。我的代码基于 Apple 的示例。

- (BOOL)collectionView:(NSCollectionView *)collectionView canDragItemsAtIndexPaths:(NSSet<NSIndexPath *> *)indexPaths withEvent:(NSEvent *)event
{
if (indexPaths != nil)
{
NSLog(@"1.0");
return YES;
}
else
return NO;
}

- (id <NSPasteboardWriting>)collectionView:(NSCollectionView *)collectionView pasteboardWriterForItemAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"2");
NSURL *testImageURL;
NSBundle* myBundle = [NSBundle mainBundle];
NSString* myImagePath = [myBundle pathForResource:@"blue-bridge" ofType:@"png"];
testImageURL = [NSURL fileURLWithPath:myImagePath];
//NSURL *anurl = [NSURL URLWithString:@"file:///Users/sysadmin/Downloads/wonderwoman.jpg"] ;

return testImageURL ;
}

正在调用 pasteboardWriterForItemAtIndexPath,然后应用崩溃;

crash log

我尝试了不同的图像,内部和外部,png 和 jpeg,所以图像本身似乎不是问题。

非常感谢建议!

最佳答案

根据堆栈跟踪,我会说它在尝试生成拖动图像时崩溃了。为确保是这种情况,请执行 -collectionView:draggingImageForItemsAtIndexwithEvent:offset:并返回任何图像,例如系统图像之一:[NSImage imageNamed:NSImageNameFolder]

如果没有崩溃,那么您肯定知道问题出在您的 NSCollectionViewItem 及其绘制 UI 的方式上。分享该代码,我们可能会帮助您。

关于objective-c - 拖入 nscollectionview 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49038174/

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