标签:
代码如下:
NSOpenPanel *openPanel = [NSOpenPanel openPanel]; [openPanel setPrompt: @"打开"]; openPanel.allowedFileTypes = [NSArray arrayWithObjects: @"txt", @"doc", nil]; openPanel.directoryURL = nil; [openPanel beginSheetModalForWindow:[self gainMainViewController] completionHandler:^(NSModalResponse returnCode) { if (returnCode == 1) { NSURL *fileUrl = [[openPanel URLs] objectAtIndex:0]; // 获取文件内容 NSFileHandle *fileHandle = [NSFileHandle fileHandleForReadingFromURL:fileUrl error:nil]; NSString *fileContext = [[NSString alloc] initWithData:fileHandle.readDataToEndOfFile encoding:NSUTF8StringEncoding]; // 将 获取的数据传递给 ViewController 的 TextView ViewController *mainViewController = (ViewController *)[self gainMainViewController].contentViewController; mainViewController.showCodeTextView.string = fileContext; } }];
标签:
原文地址:http://www.cnblogs.com/ziyeSky/p/4402102.html