我正在使用NSDocument创建一个应用程序.MyDocument.xib在NSScrollView中只有一个NSTextView.当我执行⌘S保存时,我收到一条错误消息('文档'无标题'无法保存为"Untitled.rubytext".').如何将我的应用程序保存为RTF文件?我的意思是使用NSDocument(我猜dataRepresentationOfType但我不确定?)
提前致谢.
我试图获得NSDocument在节省时间保存的路径.我尝试覆盖writeToURL但是这会传递给我一个模糊的临时文件URL,这不是它被保存的地方.同样询问这样的文件[document fileURL]只有在保存之后才有效.我可以在加载时获取路径但是我需要一些方法来进行初始保存.有没有办法在保存NSDocument时获得真正的文件路径?
我有一个tableView,我为每个单元格获取一个图像url字符串,我将所有数据保存在NSDocument目录中.
我想将所有数据存储在NSDocument目录中的文件夹中,我也想稍后删除该文件夹中的所有内容.怎么做?
这是我正在使用的方法
(void)setThumbnailTo :(UITableViewCell *)cell withRefString:(NSString *)string {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"patientPhotoFolder"];
NSString *imgPath = [string stringByReplacingOccurrencesOfString:@"amp;" withString:@""];
imgPath = [imgPath stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *key = [self sha1:imgPath];
NSString *fileToSave = [documentsPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.jpg",key]];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:fileToSave];
if (!fileExists)
{
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0ul);
dispatch_async(queue, ^{
NSData *imageData=[NSData dataWithContentsOfURL:[NSURL URLWithString:imgPath]];
UIImage *image = [[UIImage alloc] initWithData:imageData]; …Run Code Online (Sandbox Code Playgroud) 我有一个NSDocument基于应用程序,带有代表可视文档的笔尖.一旦视图出现,我想触发一些动作.
对于"正常",UIViewController我会简单地覆盖viewDidAppear:.但是,NSDocument即使每个文档都有一个视图,也没有这种方法.
我有一个NSDocument类,我需要访问主菜单窗口,这是一个在应用程序启动时打开的窗口.当我从应用程序在该窗口中操作时似乎都工作,但是当尝试从readFromFileWrapper:ofType:error:窗口执行相同的操作时,我访问似乎是零.为什么会这样?
- (BOOL)readFromFileWrapper:(NSFileWrapper *)fileWrapper ofType:(NSString *)typeName error:(NSError **)outError
{
if([[NSFileManager alloc] fileExistsAtPath:[NSString stringWithFormat:@"%@/Project.plist",[[self fileURL] path]]]) {
NSLog(@"%@", [[self fileURL] path]);
NSDictionary *project = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"%@/Project.plist",[[self fileURL] path]]];
if([[project objectForKey:@"type"] isEqualToString:@"vote"]) {
[self openProject:[[self fileURL] path] type:@"vote"];
return YES;
} else if([[project objectForKey:@"type"] isEqualToString:@"quiz"]) {
[self openProject:[[self fileURL] path] type:@"quiz"];
return YES;
} else {
return NO;
}
} else {
return NO;
}
}
Run Code Online (Sandbox Code Playgroud)
那是我的readFromFileWrapper:ofType:error:方法.这是我的openProject:type:方法:
-(void)openProject:(NSString *)filepath type:(NSString *)type
{
NSLog(@"Opening project …Run Code Online (Sandbox Code Playgroud)