标签:
1.从plist文件中读取数据到数组 @interface HMViewController () @property (nonatomic, strong) NSArray *apps; @end @implementation HMViewController //懒加载 - (NSArray *)apps { if (!_apps) { NSArray *dictArray = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"apps.plist" ofType:nil]]; NSMutableArray *appArray = [NSMutableArray array]; for (NSDictionary *dict in dictArray) { SNApp *app = [SNApp appWithDict:dict]; [appArray addObject:app]; } _apps = appArray; } return _apps; } - (void)viewDidLoad { [super viewDidLoad]; } #pragma mark - 数据源方法 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.apps.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *ID = @"app"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID]; } SNApp *app = self.apps[indexPath.row]; cell.textLabel.text = app.name; cell.detailTextLabel.text = app.download; UIImage *place = [UIImage imageNamed:@"57437179_42489b0"]; [cell.imageView setImageWithURL:[NSURL URLWithString:app.icon] placeholderImage:place]; // [cell.imageView setImageWithURL:[NSURL URLWithString:app.icon] placeholderImage:place options:SDWebImageRetryFailed progress:^(NSInteger receivedSize, NSInteger expectedSize) { //// (double)receivedSize / expectedSize; // } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) { // // }]; // ASI : Http终结者 return cell; } @end SNApp.h @interface SNApp : NSObject @property (nonatomic, copy) NSString *name; @property (nonatomic, copy) NSString *download; @property (nonatomic, copy) NSString *icon; + (instancetype)appWithDict:(NSDictionary *)dict; @end SNApp.m @implementation SNApp + (instancetype)appWithDict:(NSDictionary *)dict { SNApp *app = [[self alloc] init]; [app setValuesForKeysWithDictionary:dict]; return app; } @end
标签:
原文地址:http://www.cnblogs.com/jsnan/p/4319175.html