Cocoa:从另一个类调用App Delegate方法 [英] Cocoa: Call App Delegate Method from another Class
问题描述
我目前正试图从自定义视图中的拖放操作获取文件的路径,然后将该路径传递给我的应用程序委托。我目前正在使用以下内容:
I'm currently trying to get the path of a file from a drag and drop operation inside of a custom view, and then pass that path to my app delegate. I'm currently using the following:
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
NSPasteboard *pb = [sender draggingPasteboard];
NSString *type = [pb availableTypeFromArray:[NSArray arrayWithObject:NSFilenamesPboardType]];
NSArray *array = [[pb stringForType:type] propertyList];
//access the app delegate
NSApplication *myApplication;
myApplication = [NSApplication sharedApplication];
[myApplication uploadFiles:array];
return NO;
}
但是,我一直收到一条消息,委托没有响应uploadFiles方法。它在我的应用程序代理中声明。我以正确的方式访问NSApplication?
However, I keep getting a message that says that my app delegate doesn't respond to the "uploadFiles" method. It is declared inside of my app delegate. Am I accessing the NSApplication in the correct manner?
谢谢。
推荐答案
p>我相信问题是你指的是应用程序,而不是它的委托。这应该可以工作:
I believe the problem is that you're referring to the application but not its delegate. This should work:
Mac
[(YourAppDelegate *)[[NSApplication sharedApplication] delegate] uploadFiles:array]
实际的应用程式委托名称,并确定要#import它。
replacing YourAppDelegate with your actual app delegate name, and being certain to #import it.
这篇关于Cocoa:从另一个类调用App Delegate方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!