你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> iOS -使用屬性列表序列化簡單對象-從plist表中讀取對象

iOS -使用屬性列表序列化簡單對象-從plist表中讀取對象

編輯:IOS開發綜合
創建了plist表,寫入plist表中的數據不是一個student對象,我們要看的時候,需要以一個student對象去看。。。需要從plist表中恢復student對象的信息。我們只需要添加以下代碼:    
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" )  
  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved