1
은이 코드를 사용하여 PLIST 파일에있는 NSMutableArray 포함 된 텍스트를 저장하려고 : 예상대로 Plist 파일 경로 오류입니까?
- (IBAction)saveDoc:(id)sender
{
NSString *typedText = typingArea.text;
NSMutableArray *totalFiles = [[NSMutableArray alloc] initWithObjects:typedText, nil];
NSLog(@"Created: %@", totalFiles);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"savedFiles.plist"];
NSLog(@"Found Path: %@", path);
//[totalFiles addObject:typedText];
[totalFiles writeToFile:path atomically:YES];
NSLog(@"File Written: %@ to: %@", totalFiles, path);
[totalFiles release];
NSLog(@"Released: %@", totalFiles);
}
NSLogs의 모든
적절한 값을 반환합니다. 나는 PLIST의 내용 상자에 새있는 NSMutableArray를이 코드를 사용 :- (void)viewDidLoad {
file = [[NSBundle mainBundle] pathForResource:@"savedFiles" ofType:@"plist"];
NSLog(@"Got Path: %@", file);
array = [NSMutableArray arrayWithContentsOfFile:file];
NSLog(@"Loaded Array into new array: %@", array);
//UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"fdsfasdf" message:[dic objectForKey:@"item1"] delegate:self cancelButtonTitle:@"ldfghjfd" otherButtonTitles:nil] autorelease];
//[alert show];
[super viewDidLoad];
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
//self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
NSLogs을 첫 번째가 함께 돌아보다 약간 다른 경로로 돌아와이 코드에서. 또한 배열이 (null)이라고 말했습니다.
plist 파일의 내용을 어떻게로드해야합니까? 사전에
감사합니다,
테이트
감사합니다! Itt가 파일을 표시합니다! 이제 여러 파일을 표시하려면 어떻게해야합니까? 예 : 사용자가 파일을 만든 다음 저장하면 테이블 뷰에 표시됩니다. 그런 다음 사용자가 다른 파일을 만들고 저장하면 테이블 뷰에 다른 셀을 추가하고 이전 셀을 덮어 쓰지 않고 바꿉니다. 감사! 테이트 – tallen11