iOS-應用管理 用cell實現,前面那個用xib實現

來源:互聯網
上載者:User

標籤:

////  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

 

iOS-應用管理 用cell實現,前面那個用xib實現

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.