// // MJApp.h // 预习-03-app管理 // // Created by MJ Lee on 14-4-3. // Copyright (c) 2014年 itcast. All rights reserved. // #import <Foundation/Foundation.h> @interface MJApp : NSObject /** 图标 */ @property (copy, nonatomic) NSString *icon; /** 名称 */ @property (copy, nonatomic) NSString *name; /** 大小 */ @property (copy, nonatomic) NSString *size; /** 下载量 */ @property (copy, nonatomic) NSString *download; @property (assign, nonatomic, getter = isDownloaded) BOOL downloaded; + (instancetype)appWithDict:(NSDictionary *)dict; - (instancetype)initWithDict:(NSDictionary *)dict; @end // // MJApp.m // 预习-03-app管理 // // Created by MJ Lee on 14-4-3. // Copyright (c) 2014年 itcast. All rights reserved. // #import "MJApp.h" @implementation MJApp + (instancetype)appWithDict:(NSDictionary *)dict { return [[self alloc] initWithDict:dict]; } - (instancetype)initWithDict:(NSDictionary *)dict { if (self = [super init]) { [self setValuesForKeysWithDictionary:dict]; } return self; } @end
// // CZAppsTableViewCell.h // 应用程序下载 // // Created by YaguangZhu on 15/9/6. // Copyright (c) 2015年 YaguangZhu. All rights reserved. // #import <UIKit/UIKit.h> @class MJApp; @interface CZAppsTableViewCell : UITableViewCell @property (nonatomic,strong)MJApp *apps; + (instancetype)appsTableviewCellwithTableview:(UITableView *)tableview; @end // // CZAppsTableViewCell.m // 应用程序下载 // // Created by YaguangZhu on 15/9/6. // Copyright (c) 2015年 YaguangZhu. All rights reserved. // #import "CZAppsTableViewCell.h" #import "MJApp.h" @interface CZAppsTableViewCell() @property (weak, nonatomic) IBOutlet UIView *imgView; @property (weak, nonatomic) IBOutlet UILabel *nameLbl; @property (weak, nonatomic) IBOutlet UILabel *introLbl; @property (weak, nonatomic) IBOutlet UIButton *downloadBtn; - (IBAction)downloadClick:(id)sender; @end @implementation CZAppsTableViewCell + (instancetype)appsTableviewCellwithTableview:(UITableView *)tableview { return [tableview dequeueReusableCellWithIdentifier:@"apps"]; } - (void)setApps:(MJApp *)apps { _apps = apps; self.nameLbl.text = apps.name; self.imageView.image = [UIImage imageNamed:apps.icon]; self.introLbl.text = [NSString stringWithFormat:@"%@|%@",apps.size,apps.download]; } - (void)awakeFromNib { // Initialization code } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } - (IBAction)downloadClick:(id)sender { UIButton *btn = (UIButton *)sender; btn.enabled = NO; self.apps.downloaded = YES; } @end
// // ViewController.h // 应用程序下载 // // Created by YaguangZhu on 15/9/6. // Copyright (c) 2015年 YaguangZhu. All rights reserved. // #import <UIKit/UIKit.h> @interface ViewController : UITableViewController @end // // ViewController.m // 应用程序下载 // // Created by YaguangZhu on 15/9/6. // Copyright (c) 2015年 YaguangZhu. All rights reserved. // #import "ViewController.h" #import "MJApp.h" #import "CZAppsTableViewCell.h" @interface ViewController () @property (strong, nonatomic) NSArray *apps; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } - (BOOL)prefersStatusBarHidden { return YES; } - (NSArray *)apps { if (_apps == nil) { NSArray *dictArray = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"apps_full.plist" ofType:nil]]; NSMutableArray *appArray = [NSMutableArray array]; for (NSDictionary *dict in dictArray) { MJApp *app = [MJApp appWithDict:dict]; [appArray addObject:app]; } _apps = appArray; } return _apps; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.apps.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { CZAppsTableViewCell *cell = [CZAppsTableViewCell appsTableviewCellwithTableview:tableView]; MJApp *model = self.apps[indexPath.row]; cell.apps = model; //cell.delegate = self; //cell.app = self.apps[indexPath.row]; return cell; } //- (void)appCellDidClickedDownloadBtn:(MJAppCell *)cell //{ // // 1.取出模型 // MJApp *app = cell.app; // // // 2.添加标签 // UILabel *label = [[UILabel alloc] init]; // label.text = [NSString stringWithFormat:@"成功下载%@", app.name]; // label.font = [UIFont systemFontOfSize:12]; // label.textAlignment = NSTextAlignmentCenter; // label.textColor = [UIColor whiteColor]; // label.backgroundColor = [UIColor blackColor]; // label.frame = CGRectMake(0, 0, 150, 25); // label.center = CGPointMake(160, 240); // label.alpha = 0.0; // label.layer.cornerRadius = 5; // label.clipsToBounds = YES; // [self.view addSubview:label]; // // // 3.动画 // [UIView animateWithDuration:0.5 animations:^{ // label.alpha = 0.5; // } completion:^(BOOL finished) { // [UIView animateWithDuration:0.5 delay:0.5 options:UIViewAnimationOptionCurveLinear animations:^{ // label.alpha = 0.0; // } completion:^(BOOL finished) { // [label removeFromSuperview]; // }]; // }]; //} - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end