【发布时间】:2011-03-16 21:08:01
【问题描述】:
目前我的应用程序界面上有一个按钮可以打开文件,这是我的打开代码:
在我的 app.h 中:
- (IBAction)selectFile:(id)sender;
在我的 app.m 中:
@synthesize window;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
}
- (IBAction)selectFile:(id)sender {
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
NSArray *fileTypes = [NSArray arrayWithObjects:@"xml",nil];
NSInteger result = [openPanel runModalForDirectory:NSHomeDirectory() file:nil types:fileTypes ];
if(result == NSOKButton){
NSString * input = [openPanel filename];
如何编辑我的代码以允许通过应用程序图标拖放打开?
注意:我编辑了 .plist 文件并为“xml”添加了一行,但它改变了任何内容,当我的文件被拖放到图标上时出现错误。
注意 2:我将“文件 -> 打开...”链接到 selectFile:请参阅我的代码
注意 3:我的应用不是基于文档的应用
感谢您的帮助!
米斯基亚
【问题讨论】:
-
为什么不使用 NSDocument?不够灵活?
标签: objective-c cocoa xcode macos nsdocument