2012-10-20 2 views
2

내 응용 프로그램의 Documents 디렉토리에서 HTML 파일을 표시하려면 어떻게해야합니까? 다음은 내가 사용하고 아무것도에 표시되지 않은 코드는 내 왜이iPhone의 UIWebView에서 문서 디렉토리의 로컬 HTML 파일 표시

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 
    NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory, @"Notes.html"]; 

    NSURL *url = [NSURL URLWithString:filePath]; 
    NSURLRequest *request = [NSURLRequest requestWithURL:url]; 
    [notesListWeb loadRequest:request]; 

UIWebView을 작동하지?

다른 답변을 찾았지만 문서 디렉토리에 없습니다.

귀하의 도움에 감사드립니다.

+0

'filePath'를 로그에 저장하려고 했습니까? –

답변

6

파일 경로와 함께 NSURL 객체를 생성 할 수있는 적절한 방법은 다음과 같습니다 작성 방법

NSURL *url = [NSURL fileURLWithPath:filePath]; 

또한 변경해야합니다 당신의 적인 filePath :

NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"Notes.html"]; 

또한 염두에 두어야 그 파일 이름은 실제 iOS 장치에서 대소 문자를 구분합니다. 파일 이름은 실제로 Notes.html과 notes.html입니까?

관련 문제