문서 폴더에 저장할 파일이 여러 개 있습니다.이 파일 목록은 변경 가능한 배열에 저장됩니다. 파일은 닫힌 iPhone 응용 프로그램의 메모리에 남아 있어야합니다. 첫 번째 파일은 저장되지만 뷰 컨트롤러를 변경 한 다음 다시 돌아 가면 변경 가능한 배열이 비게됩니다. 어떻게 데이터를 Documents 폴더에 메모리에 보관합니까? DetailExpViewController.mDocuments 폴더에 파일 목록을 작성하고 메모리에 보관하십시오.
에서 DetailExpViewController.h//....
@property (nonatomic, strong)NSMutableArray *arrayFavorites;
@property (nonatomic, assign)BOOL existsArray;
//....
@end
에서
- (void)viewDidLoad
{
//.....
if (!self.existsArray){
/*when I load the view controller this array is always nil even
has already been created*/
self.arrayFavorites =[[NSMutableArray alloc]init];
}else{
NSLog(@"The array exists");
}
//....
}
-(void) addFavorites:(id)sender{
//.....
NSArray *paths = NSSearchPathForDirectoriesInDomains
(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString * text= [NSString stringWithFormat:@"%@.txt",self.name];
NSString * documentsPath = [documentsDirectory stringByAppendingPathComponent: text];
[self.arrayFavorites addObject:text];
[self.arrayFavorites writeToFile:documentsPath atomically:YES];
self.existsArray=YES;
for (id obj in self.arrayFavorites) {
NSLog(@"%@", self.arrayFavorites);
//only writes the file at the time, then it is deleted
}
}
항상 nil을하고 다음 U는 그것을 파일 –
을 ALLOC. 내 응용 프로그램에는 사용자가 단추를 누르면 "즐겨 찾기 추가"라는 단추가있는보기 컨트롤러가 있으며 파일은 문서 폴더에 저장해야합니다. 그렇지 않으면 그렇지 않습니다. 나는 사용자를 저장할 것이 무엇인지를 미리 알 수 없으므로 가변 배열을 만들었습니다. 이러한 파일은 문서 폴더에 영구적으로 남아 있어야합니다. 어떻게해야합니까? –
데이터를 저장하기위한 SQLite는 사용하지 말아 이유 –