1.打开工程之后,File --> New -->File 在弹出界面中左栏选中Mac os X 下的Resourse一栏,选中Property List,点击Next命名为testInfo.plist,然后打开testInfo.plist文件,在文件上右键Add Row,添加如下头所示数据(我用的Xcode版本是4.3.1,老版本的可能有的不一样)
[img]
![](http://dl.iteye.com/upload/attachment/0079/3238/6bdfcca0-3908-3a95-be27-63d3c7fa07a4.png)
[/img]
在View的最后面添加代码
// 读取plist文件 NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"testInfo" ofType:@"plist"]; NSMutableDictionary *data=[[NSMutableDictionary alloc] initWithContentsOfFile:plistPath]; // 打印出plist文件 NSLog(@"%@",data); //读取学生字典的内容到StudentInfo中qu NSMutableDictionary *StudentInfo = [data objectForKey:@"Student"]; sNameTextField.text = [NSString stringWithFormat:@"%@",[StudentInfo objectForKey:@"Name"]]; sAgeTextField.text = [NSString stringWithFormat:@"%@",[StudentInfo objectForKey:@"Age"]]; sSexTextField.text = [NSString stringWithFormat:@"%@",[StudentInfo objectForKey:@"Sex"]]; NSMutableDictionary *teacherInfo = [data objectForKey:@"teacher"]; //在teacher字典中,把键为Name的值赋给tNameTextField的text上 tNameTextField.text = [NSString stringWithFormat:@"%@",[teacherInfo objectForKey:@"Name"]]; tSexTextField.text = [NSString stringWithFormat:@"%@",[teacherInfo objectForKey:@"Sex"]];
保存运行:
[img]
![](http://dl.iteye.com/upload/attachment/0079/3240/3f3b54e8-b12f-38d2-ae9e-417506b5284b.png)
[/img]