0

我知道这是一个相对简单的问题,但我就是不知道如何解决这个问题:

我的一个视图将收到一个 dragOperation 并且 performDragOperation 方法应该将 NSURL 传递给我的 AppDelegate ,它将它放在一个 mutArray ...

问题是,我传递了一个引用并且对象在 performDragOperation 完成的那一刻消失了。所以我尝试了几件事:

在执行拖动操作中:

//Puts the reference itself in the folderPaths Array
AppDelegate *appDelegate = [NSApp delegate];
[[appDelegate folderPaths] addObject:referenceTotheNSURLObject];
/* tried creating a NSString and putting it in too. Same result because local variables will disappear */

所以我在 AppDelegate 中创建了一个方法并尝试了不同的方法:

- (void)addFilePath:(NSURL *)filePath {
    NSURL *copyOfURL = [filePath copy];
    [[self folderPaths] addObject:copyOfURL];
}

这对我来说是最有意义的,我能想到为什么这不起作用的唯一原因是,因为 copyOfURL 本身是一个指针,它指向一个 localObject,它会在 addFilePath 方法完成时消失?但我不允许使用

NSURL copyOfURL = [filePath copy];

我还尝试再次重新创建一个 NSString 对象。结果相同。

- (void)addFilePath:(NSURL *)filePath {
    NSString *pathString = [filePath absoluteString];
    [[self folderPaths] addObject:pathString];
}

我知道这将是一些相对简单的解决方案,但我被卡住了,无法弄清楚。谢谢你的时间!

4

0 回答 0