在我的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:我将“file – > Open …”链接到selectfile:这是指我的代码
注3:我的应用程序不是基于文档的应用程序
谢谢你的帮助!
Miskia
接下来实现以下代理:
– 应用程序:openfile :(丢失一个文件)
– 应用程序:openfiles :(删除了多个文件)
参考:
NSApplicationDelegate Protocol Reference
回复评论:
一步一步的例子,希望它能让一切清楚:)
添加到.pList文件:
<key>CFBundledocumentTypes</key> <array> <dict> <key>CFBundleTypeExtensions</key> <array> <string>xml</string> </array> <key>CFBundleTypeIconfile</key> <string>application.icns</string> <key>CFBundleTypeMIMETypes</key> <array> <string>text/xml</string> </array> <key>CFBundleTypename</key> <string>XML file</string> <key>CFBundleTypeRole</key> <string>VIEwer</string> <key>LSIsAppleDefaultForType</key> <true/> </dict> </array>
添加到… AppDelegate.h
- (BOol)processfile:(Nsstring *)file;- (IBAction)openfileManually:(ID)sender;
添加到… AppDelegate.m
- (IBAction)openfileManually:(ID)sender;{ NSOpenPanel *openPanel = [NSOpenPanel openPanel]; NSArray *fileTypes = [NSArray arrayWithObjects:@"xml",nil]; NSInteger result = [openPanel runModalForDirectory:NSHomeDirectory() file:nil types:fileTypes ]; if(result == NSOKbutton){ [self processfile:[openPanel filename]]; }}- (BOol)application:(NSApplication *)theApplication openfile:(Nsstring *)filename{ return [self processfile:filename];}- (BOol)processfile:(Nsstring *)file{ NSLog(@"The following file has been dropped or selected: %@",file); // Process file here return YES; // Return YES when file processed succesfull,else return NO.}总结
以上是内存溢出为你收集整理的objective-c – Cocoa / Obj-C – 将文件拖动到应用程序图标时打开文件全部内容,希望文章能够帮你解决objective-c – Cocoa / Obj-C – 将文件拖动到应用程序图标时打开文件所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)