2013-07-02 9 views
2

나는 각각의 문서를 NSFileWrapper 디렉토리로 저장하고 문서 텍스트와 문서 제목을 디렉토리에 별도의 파일로 저장하는 텍스트 편집기 응용 프로그램을 만들고 있습니다. loadFromContents: (id) contentscontents 부분이 NSFileWrapper가 될 것으로 예상되지만 그렇지 않습니다. 내 코드는 다음과 같습니다 (이 UIDocument의 서브 클래스에 속하는) :UIDocument loadFromContents는 NSFileWrapper를 반환해야합니다. 대신 NSConcreteData를 반환합니다

다음

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSConcreteData fileWrappers]: unrecognized selector sent to instance 0x9367150'

가 도움이 내 contentsForType: 기능이되어있는 경우 :

// loads document data to application data model 

- (BOOL) loadFromContents:(id)contents ofType:(NSString *)typeName error:(NSError *__autoreleasing *)outError { 
    // from the contents, extract it so that we have the properties initialized 
    self.fileWrapper = (NSFileWrapper *) contents; 
    NSLog(@"%@", [contents class]); //** returns NSConcreteData 

    // get the fileWrapper's children 
    NSDictionary *contentsOfFileWrapper = [contents fileWrappers]; 

    // assign things to the document! 
    // can also be done lazily through getters 

    self.text = [contentsOfFileWrapper objectForKey:TEXT_KEY]; 
    self.title = [contentsOfFileWrapper objectForKey:TITLE_KEY]; 
    if ([self.delegate respondsToSelector:@selector(noteDocumentContentsUpdated:)]){ 
     [self.delegate noteDocumentContentsUpdated:self]; 
    } 
    return YES; 
} 

나는이 메소드를 호출하려고,이 오류가 발생합니다 :

- (id) contentsForType:(NSString *)typeName error:(NSError *__autoreleasing *)outError { 
    if (!self.fileWrapper) { 
     self.fileWrapper = [[NSFileWrapper alloc] initDirectoryWithFileWrappers:nil]; 
    } 

    NSDictionary *childrenFileWrappers = [self.fileWrapper fileWrappers]; 

    // now if we have a text but it is not represented, in the file wrapper, put it in. Same with the images. 
    if ([childrenFileWrappers objectForKey:TEXT_KEY] == nil && self.text != nil) { 
     NSData *textData = [self.text dataUsingEncoding:kCFStringEncodingUTF16]; 
     NSFileWrapper *textFileWrapper = [[NSFileWrapper alloc] initRegularFileWithContents:textData]; 
     [textFileWrapper setPreferredFilename:TEXT_KEY]; 
     [self.fileWrapper addFileWrapper:textFileWrapper]; 
    } 

    if ([childrenFileWrappers objectForKey:TITLE_KEY] == nil && self.title != nil) { 
     NSData *titleData = [self.title dataUsingEncoding:kCFStringEncodingUTF16]; 
     NSFileWrapper *titleFileWrapper = [[NSFileWrapper alloc] initRegularFileWithContents:titleData]; 
     [titleFileWrapper setPreferredFilename:TITLE_KEY]; 
     [self.fileWrapper addFileWrapper:titleFileWrapper]; 
    } 

    return self.fileWrapper; 

} 

고마워요!

답변

1

문제가 해결되었습니다. 내 문서 폴더에 .DS_Store 파일이 있었는데 결과가 엉망이었습니다. 일단 if 문을 추가하여 모든 문제를 해결했습니다.