BOOL isDirectory; //判斷AppHome/Documents/student.plist文件是否存在(txt純文本)
if ([fileManager fileExistsAtPath:studentFilePath isDirectory:&isDirectory] && !isDirectory) {
NSLog(@"存在 student.plist !!");
/ 通過plist表生成數組對象
NSArray *studentList = [NSArray arrayWithContentsOfFile:studentFilePath];
//取出數組中對應字段的數組
NSArray *studentName = [studentList objectAtIndex:0];
NSArray *studentID = [studentList objectAtIndex:1];
NSArray *studentSex = [studentList objectAtIndex:2];
NSArray *studentImagePath = [studentList objectAtIndex:3];
//通過遍歷每個字段數組,恢復student對象
NSMutableArray *studentArray = [[NSMutableArray alloc] init];
for (int i = 0; i < [studentName count]; i++) {
Students *student = [[Students alloc] initWithName:[studentName objectAtIndex:i] ID:[[studentID objectAtIndex:i] intValue] Sex:[studentSex objectAtIndex:i] Photo:[studentImagePath objectAtIndex:i]];
[studentArray addObject:student];
}
NSLog(@"stuents:%s",[[studentArray description] UTF8String]);
}else{
打印: 2013-10-28 15:31:35.034 StudentPlist[2050:70b] stuents:( "name:seal,id:110401,sex:girl,imagepath:seal.png", "name:willing,id:110402,sex:boy,imagepath:willing.png", "name:lisa,id:110403,sex:girl,imagepath:lisa.png" )