[ios]plist 加载

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSString *Plist=[[NSBundle mainBundle] pathForResource:@"studentList" ofType:@"plist"];
    //通过文件名(资源)获取路径
    NSDictionary *dt=[[NSDictionary alloc]initWithContentsOfFile:Plist];
    //通过通过文件创建字典。
    NSDictionary *studentD=[dt objectForKey:@"student"];
    //通过通过key找到二级字典
    
    self.nameContent.text=(NSString *)[studentD objectForKey:@"name"];
//    NSLog(@"%@",studentPlist);
    
	// Do any additional setup after loading the view, typically from a nib.
}
 

plist文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>student</key>
	<dict>
		<key>age</key>
		<string>22</string>
		<key>sex</key>
		<string>boy</string>
		<key>name</key>
		<string>poolo</string>
	</dict>
</dict>
</plist>
 

 

猜你喜欢

转载自poolo.iteye.com/blog/1699694