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

数据处理

时间:2015-03-06 21:56:37      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:

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

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