码迷,mamicode.com
首页 > 其他好文 > 详细

plist文件的实现

时间:2015-05-24 11:26:27      阅读:78      评论:0      收藏:0      [点我收藏+]

标签:

在initWithNibName中获取plist文件中的内容

 1 //        获取plist文件
 2         NSDictionary * dic = [NSDictionary dictionaryWithContentsOfFile:@"plist文件地址"];
 3         NSLog(@"%@",dic);
 4         self.BookDic = [NSMutableDictionary dictionary];
 5 //        将文件中的所有内容都取出
 6         for (NSString * key  in dic) {
 7             NSArray * arr = [dic objectForKey:key];
 8             self.bookArr = [NSMutableArray array];
 9             for (NSDictionary * temDic in arr) {
10                 Books * book = [[Books alloc]init];
11                 book.name = [temDic objectForKey:@"name"];
12                 book.content = [temDic objectForKey:@"content"];
13                 book.img = [temDic objectForKey:@"photo"];
14                 [self.bookArr addObject:book];
15                 
16                 [book release];
17                 NSLog(@"%@",book.name);
18                 
19             }
20             [self.BookDic setObject:self.bookArr forKey:key];
21         }
22         self.view.backgroundColor = [UIColor cyanColor];

设置section的个数

1 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
2 
3 //    设置section的个数
4     return self.BookDic.allKeys.count;
5 }

设置row的个数

1 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
2     
3 //    设置每个section的行数
4     NSString *key = [[self.BookDic allKeys] objectAtIndex:section];
5     return [[self.BookDic objectForKey:key] count];
6 }

对cell进行传值

 1 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
 2     
 3     BookTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"bookCell"];
 4     
 5     if (!cell) {
 6         cell = [[BookTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"bookCell"];
 7     }
 8     
 9 //    进行传值
10     NSString *key = [[self.BookDic allKeys] objectAtIndex:indexPath.section];
11     NSMutableArray *arr = [self.BookDic objectForKey:key];
12     
13     Books * bok = [arr objectAtIndex:indexPath.row];
14     cell.book = bok;
15     // Configure the cell...
16     
17     return cell;
18 }

 

plist文件的实现

标签:

原文地址:http://www.cnblogs.com/AnchoriteFiliGod/p/4525522.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!