您的位置:首页 > 移动开发 > IOS开发

iOS 读取plist 方法

2016-07-06 00:00 435 查看
摘要: 读取plist

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

//读取自定义的 plist文件的写法

//    NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"customInfo" ofType:@"plist"];
//    NSDictionary *dictionary = [[NSDictionary alloc] initWithContentsOfFile:plistPath];
//    NSLog(@"dictionary = %@",dictionary);
//将学生信息填入
//    NSDictionary *tmpInfo = [dictionary objectForKey:@"Student"];
//    self.txtStuName.text = [NSString stringWithFormat:@"%@", [tmpInfo objectForKey:@"Name"]];
//    self.txtStuSex.text = [NSString stringWithFormat:@"%@", [tmpInfo objectForKey:@"Sex"]];
//    self.txtStuNum.text = [NSString stringWithFormat:@"%@", [tmpInfo objectForKey:@"Num"]];
//将导师信息填入
//    tmpInfo = [dictionary objectForKey:@"Mentor"];
//    self.txtMtName.text = [NSString stringWithFormat:@"%@", [tmpInfo objectForKey:@"Name"]];
//    self.txtMtSex.text = [NSString stringWithFormat:@"%@", [tmpInfo objectForKey:@"Sex"]];

//读取系统产生的 plist文件的写法

NSDictionary *plistDic = [[NSBundle mainBundle] infoDictionary];
NSLog(@"plistDic = %@",plistDic);

//将学生信息填入
NSDictionary *tmpInfo = [plistDic objectForKey:@"Student"];
self.txtStuName.text = [NSString stringWithFormat:@"%@", [tmpInfo objectForKey:@"Name"]];
self.txtStuSex.text = [NSString stringWithFormat:@"%@", [tmpInfo objectForKey:@"Sex"]];
self.txtStuNum.text = [NSString stringWithFormat:@"%@", [tmpInfo objectForKey:@"Num"]];
//将导师信息填入
tmpInfo = [plistDic objectForKey:@"Mentor"];
self.txtMtName.text = [NSString stringWithFormat:@"%@", [tmpInfo objectForKey:@"Name"]];
self.txtMtSex.text = [NSString stringWithFormat:@"%@", [tmpInfo objectForKey:@"Sex"]];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: