一、plist文件详情
二、UITableView读取plist文件代码
#import "ViewController.h"
@interfaceViewController ()
{
NSArray *_data;
}
@end
@implementation ViewController
- (void)viewDidLoad
{
[superviewDidLoad];
_data = [NSArrayarrayWithContentsOfFile:[[NSBundlemainBundle] pathForResource:@"360app.plist"ofType:nil]];
// NSMutableArray *array = [NSMutableArray array];
//
// for (int i = 0; i<_data.count; i++) {
// NSDictionary *oldDict = _data[i];
//
// NSMutableDictionary *newDict = [NSMutableDictionary dictionary];
// [newDict setDictionary:oldDict];
// [newDict setObject:[NSString stringWithFormat:@"%d.png", i] forKey:@"local_icon"];
//
// [array addObject:newDict];
// }
//
// [array writeToFile:@"/Users/apple/Desktop/360app.plist" atomically:YES];
// NSLog(@"%d", _data.count);
// for (int i = 0; i<_data.count; i++) {
//// NSLog(@"------");
// NSDictionary *app = _data[i];
//
// NSLog(@"%@", app[@"icon"]);
//
// NSData *imgData = [NSData dataWithContentsOfURL:[NSURL URLWithString:app[@"icon"]]];
//
// NSString *filename = [NSString stringWithFormat:@"/Users/apple/Desktop/360img/%d.png", i];
// [imgData writeToFile:filename atomically:YES];
// }
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _data.count;
}
#pragma mark 每当有一个cell进入视野范围内就会调用,返回当前这行显示的cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// 0.用static修饰的局部变量,只会初始化一次
static NSString *ID = @"cell";
// 1.拿到一个标识先去缓存池中查找对应的Cell
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
// 2.如果缓存池中没有,才需要传入一个标识创建新的Cell
if (cell == nil) {
cell = [[UITableViewCellalloc] initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:ID];
}
// 3.覆盖数据
NSDictionary *app = _data[indexPath.row];
// NSData *imgData = [NSData dataWithContentsOfURL:[NSURL URLWithString:app[@"icon"]]];
// NSString *filename = [NSString stringWithFormat:@"%d.png", indexPath.row];
cell.imageView.image = [UIImage imageNamed:app[@"local_icon"]];
cell.textLabel.text = app[@"name"];
cell.detailTextLabel.text = app[@"download"];
return cell;
}
@end