iOS UI-应用管理(使用Cell模板)

一、Model

 1 //
 2 //  BWApp.h
 3 //  IOS_0112_应用管理
 4 //
 5 //  Created by ma c on 16/1/12.
 6 //  Copyright (c) 2016年 博文科技. All rights reserved.
 7 //
 8
 9 #import <Foundation/Foundation.h>
10
11 @interface BWApp : NSObject
12
13 @property (nonatomic, copy) NSString *size;
14 @property (nonatomic, copy) NSString *download;
15 @property (nonatomic, copy) NSString *name;
16 @property (nonatomic, copy) NSString *icon;
17 //标记是否被下载过
18 @property (nonatomic, assign) BOOL isDownloaded;
19
20 - (instancetype)initWithDict:(NSDictionary *)dict;
21 + (instancetype)appWithDict:(NSDictionary *)dict;
22
23 @end
24
25
26 //
27 //  BWApp.m
28 //  IOS_0112_应用管理
29 //
30 //  Created by ma c on 16/1/12.
31 //  Copyright (c) 2016年 博文科技. All rights reserved.
32 //
33
34 #import "BWApp.h"
35
36 @implementation BWApp
37
38 - (instancetype)initWithDict:(NSDictionary *)dict
39 {
40     if (self = [super init]) {
41         [self setValuesForKeysWithDictionary:dict];
42     }
43     return self;
44 }
45
46 + (instancetype)appWithDict:(NSDictionary *)dict
47 {
48     return [[self alloc] initWithDict:dict];
49 }
50
51 @end

二、View

 1 #import <UIKit/UIKit.h>
 2 @class BWAppCell;
 3 @protocol appCellDelegate <NSObject>
 4
 5 - (void)btnDownloadClick:(BWAppCell *)appCell;
 6
 7 @end
 8
 9 @class BWApp;
10 @interface BWAppCell : UITableViewCell
11
12 @property (nonatomic, strong) BWApp *app;
13 @property (nonatomic, strong) id<appCellDelegate> delegate;
14
15 @end
16
17 //
18 //  BWAppCell.m
19 //  IOS_0112_应用管理
20 //
21 //  Created by ma c on 16/1/12.
22 //  Copyright (c) 2016年 博文科技. All rights reserved.
23 //
24
25 #import "BWAppCell.h"
26 #import "BWApp.h"
27
28 @interface BWAppCell ()
29 @property (weak, nonatomic) IBOutlet UIImageView *appIcon;
30 @property (weak, nonatomic) IBOutlet UILabel *appName;
31 @property (weak, nonatomic) IBOutlet UILabel *appDesc;
32
33 @property (weak, nonatomic) IBOutlet UIButton *appDownload;
34 - (IBAction)appDownload:(id)sender;
35
36 @end
37
38 @implementation BWAppCell
39
40 - (void)setApp:(BWApp *)app
41 {
42     _app = app;
43
44     //给子控件设置数据
45     self.appIcon.image = [UIImage imageNamed:_app.icon];
46     self.appName.text = _app.name;
47     self.appDesc.text = [NSString stringWithFormat:@"大小:%@ | 下载量:%@",_app.size,_app.download];
48
49     //更新下载按钮状态
50     if (app.isDownloaded) {
51         self.appDownload.enabled = NO;
52     }
53     else
54         self.appDownload.enabled = YES;
55
56
57 }
58
59
60 #pragma mark - 下载按钮点击事件
61 - (IBAction)appDownload:(id)sender {
62     //1.禁用按钮
63     self.appDownload.enabled = NO;
64     //已经被点击过了
65     self.app.isDownloaded = YES;
66     if ([self.delegate respondsToSelector:@selector(btnDownloadClick:)]) {
67         [self.delegate btnDownloadClick:self];
68     }
69 }
70
71 - (void)awakeFromNib {
72     // Initialization code
73 }
74
75 - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
76     [super setSelected:selected animated:animated];
77
78     // Configure the view for the selected state
79 }
80
81 @end

三、Controller

  1 //
  2 //  ViewController.m
  3 //  IOS_0112_应用管理
  4 //
  5 //  Created by ma c on 16/1/12.
  6 //  Copyright (c) 2016年 博文科技. All rights reserved.
  7 //
  8
  9 #import "ViewController.h"
 10 #import "BWApp.h"
 11 #import "BWAppCell.h"
 12 @interface ViewController ()<appCellDelegate>
 13
 14 @property (nonatomic, strong) NSArray *appArray;
 15
 16 @end
 17
 18 @implementation ViewController
 19
 20 #pragma mark - appCellDelegate代理方法
 21 - (void)btnDownloadClick:(BWAppCell *)appCell
 22 {
 23     //1.创建一个Label
 24     UILabel *lblMsg = [[UILabel alloc] initWithFrame:CGRectMake(140, (self.view.frame.size.height - 37)/2, 95, 37)];
 25     lblMsg.text = @"正在下载...";
 26     lblMsg.textAlignment = NSTextAlignmentCenter;
 27     lblMsg.backgroundColor = [UIColor blackColor];
 28     lblMsg.textColor = [UIColor redColor];
 29     //设置透明度
 30     lblMsg.alpha = 0.0;
 31     //设置圆角
 32     lblMsg.layer.cornerRadius = 10;
 33     lblMsg.layer.masksToBounds = YES;
 34     //[self.view addSubview:lblMsg];
 35
 36     [[[UIApplication sharedApplication] keyWindow] addSubview:lblMsg];
 37
 38     //动画方式显示Label
 39 //    [UIView animateWithDuration:1.0 animations:^{
 40 //        lblMsg.alpha = 0.6;
 41 //    }];
 42
 43     [UIView animateWithDuration:1.0 animations:^{
 44         lblMsg.alpha = 0.6;
 45     } completion:^(BOOL finished) {
 46         //动画执行完毕以后
 47         //再开启一个新动画
 48         [UIView animateWithDuration:1.0 delay:0.5 options:UIViewAnimationOptionCurveLinear animations:^{
 49             lblMsg.alpha = 0;
 50         } completion:^(BOOL finished) {
 51             [lblMsg removeFromSuperview];
 52         }];
 53     }];
 54 }
 55
 56 #pragma mark - 懒加载
 57 - (NSArray *)appArray
 58 {
 59     if (_appArray == nil) {
 60         NSString *path = [[NSBundle mainBundle] pathForResource:@"apps_full.plist" ofType:nil];
 61         NSArray *arrDict = [NSArray arrayWithContentsOfFile:path];
 62         NSMutableArray *arrModel = [NSMutableArray array];
 63
 64         for (NSDictionary *dict in arrDict) {
 65             BWApp *app = [BWApp appWithDict:dict];
 66             [arrModel addObject:app];
 67         }
 68         _appArray = arrModel;
 69     }
 70     return _appArray;
 71 }
 72
 73 #pragma mark - viewDidLoad
 74 - (void)viewDidLoad {
 75     [super viewDidLoad];
 76     //NSLog(@"%@",self.appArray);
 77     self.tableView.rowHeight = 60;
 78 }
 79 #pragma mark - 数据源方法
 80 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
 81 {
 82     return 1;
 83 }
 84 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
 85 {
 86     return self.appArray.count;
 87 }
 88
 89 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 90 {
 91     //1.获取数据模型
 92     BWApp *model = self.appArray[indexPath.row];
 93     //2.通过storyboard中cell模板创建单元格
 94     static NSString *ID = @"app_cell";
 95     BWAppCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
 96     //3.设置数据
 97     cell.app = model;
 98     cell.delegate = self;
 99     //4.返回数据
100     return cell;
101 }
102
103 - (void)didReceiveMemoryWarning {
104     [super didReceiveMemoryWarning];
105     // Dispose of any resources that can be recreated.
106 }
107
108 @end

时间: 2024-08-25 01:19:04

iOS UI-应用管理(使用Cell模板)的相关文章

iOS-应用管理 用cell实现,前面那个用xib实现

// // 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; /** 名称 */ @pro

iOS开发实战——CollectionView中cell的间距设置

我在前面多篇博客中详细讲解了CollectionView的使用与自定义CollectionViewCell的设计,可以参考<iOS开发实战--CollectionView点击事件与键盘隐藏结合案例><iOS高级开发--CollectionView修改cell的文本及模型重构>这几篇博客.但是今天还是需要来讲讲CollectionView实现中的一个小小的坑,这是我最近在网上浏览时发现很多开发者经常犯的错,所以我觉得有必要来好好谈一谈. 一个CollectionView控件中,两个c

【腾讯TMQ】解放程序猿(媛)的双手—iOS UI自动化测试

解放程序猿(媛)的双手-iOS UI自动化测试 前言 随着移动互联网时代的蓬勃发展,移动终端的自动化测试也在业界日益活跃,总体来看在Android平台上的自动化工具和实践比较多,但是说到iOS平台无论从自动化工具的数量还是质量上就陡降了.究其原因,无外乎是iOS系统的封闭性,加上相对Android用户的数量少,导致对这个平台系统的自动化进展缓慢,据笔者了解到的情况,很多iOS平台的测试人员还处于纯手工测试模式,自动化程度和Android平台无法相论,更别提和PC端相比了. 然而越是困难的事,越是

iOS UI Tab开发

iOS UI Tab开发(iOS 8) tab这种样式,类似于单选,可以叫radio-style,这是一个现在主流的layout-design,它让APP内容结构清晰,开发分工逻辑明确,经典的就是微信,时钟等 综述一下: 1.UITabBarController继承UIViewController,是一个ViewController container 2.UITabBarController拥有一个(readonly)的TabBar,TabBar拥有一到多个TabBarItem 3.每一个It

50个高端大气上档次的管理后台界面模板

大部分站点都有一个管理面板或者管理界面用于查看和管理站点信息.可是通常大家并非非常重视这个后台管理界面的设计,一般能用即可了.可是事实上美丽的管理界面也能大大的提升工作人员的工作效率啊.通过使用美丽的管理面板你能够省掉非常多的时间,同事,设计良好的界面也适合在移动终端上使用,从而降低对PC的依赖和提供管理的灵活性. 这里收集了50个高端大气上档次,简洁时尚国际化的后台管理界面模板,希望你能喜欢并获取灵感. 1. Katniss Premium Admin Template 2. Esthetic

说说iOS与内存管理(上)

http://www.cocoachina.com/ios/20150625/12234.html 说起内存管理,看似老生常谈,而真正掌握内存管理的核心其实并不简单.ARC/MRR以及“谁分配谁就负责释放”这种基本原则是很重要的,但不是本文要讨论的重点.之前本人还没在小站发过相关的文章,本篇文章中,我本人是想结合实际开发和调试中遇到的一些细节问题,来谈谈iOS的内存管理内在机制和调试方法. 上一篇文章已经是4月份的了,时间飞快又过去了好久,小站5月份没有文章更新,罪过罪过.最近小站的站长我又转换

Unity3d:UI面板管理整合进ToLua

本文基于 https://github.com/chiuan/TTUIFramework https://github.com/jarjin/LuaFramework_UGUI 进行的二次开发,Thanks! 需求: 1.需要一个UI面板管理器,逻辑写在lua里面,方便热更新. 2.管理器控制面板的打开(show),隐藏(Hide),销毁(Destroy),刷新(Rest). 3.要有类似网页浏览器那样,点击后退(<---),会显示上一个页面.用到数据结构:栈(Stack),先进后出.打开顺序是

理解 iOS 的内存管理

理解 iOS 的内存管理 远古时代的故事 那些经历过手工管理内存(MRC)时代的人们,一定对 iOS 开发中的内存管理记忆犹新.那个时候大约是 2010 年,国内 iOS 开发刚刚兴起,tinyfool 大叔的大名已经如雷贯耳,而我还是一个默默无闻的刚毕业的小子.那个时候的 iOS 开发过程是这样的: 我们先写好一段 iOS 的代码,然后屏住呼吸,开始运行它,不出所料,它崩溃了.在 MRC 时代,即使是最牛逼的 iOS 开发者,也不能保证一次性就写出完美的内存管理代码.于是,我们开始一步一步调试

IOS Ui控件 修改位置和尺寸,代码添加控件

所有的UI控件最终都继承自UIView,UI控件的公共属性都定义在UIView中, UIView的常见属性 UIView *superview; 获得自己的父控件对象 NSArray *subviews; 获得自己的所有子控件对象 NSInteger tag; 控件的ID(标识),父控件可以通过tag来找到对应的子控件 CGAffineTransform transform; 控件的形变属性(可以设置旋转角度.比例缩放.平移等属性) CGRect frame; 控件所在矩形框在父控件中的位置和尺