一、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. // BWApp.m
  27. // IOS_0112_应用管理
  28. //
  29. // Created by ma c on 16/1/12.
  30. // Copyright (c) 2016年 博文科技. All rights reserved.
  31. //
  32.  
  33. #import "BWApp.h"
  34.  
  35. @implementation BWApp
  36.  
  37. - (instancetype)initWithDict:(NSDictionary *)dict
  38. {
  39. if (self = [super init]) {
  40. [self setValuesForKeysWithDictionary:dict];
  41. }
  42. return self;
  43. }
  44.  
  45. + (instancetype)appWithDict:(NSDictionary *)dict
  46. {
  47. return [[self alloc] initWithDict:dict];
  48. }
  49.  
  50. @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. #pragma mark - 下载按钮点击事件
  59. - (IBAction)appDownload:(id)sender {
  60. //1.禁用按钮
  61. self.appDownload.enabled = NO;
  62. //已经被点击过了
  63. self.app.isDownloaded = YES;
  64. if ([self.delegate respondsToSelector:@selector(btnDownloadClick:)]) {
  65. [self.delegate btnDownloadClick:self];
  66. }
  67. }
  68.  
  69. - (void)awakeFromNib {
  70. // Initialization code
  71. }
  72.  
  73. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  74. [super setSelected:selected animated:animated];
  75.  
  76. // Configure the view for the selected state
  77. }
  78.  
  79. @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(, (self.view.frame.size.height - )/, , )];
  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 = ;
  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 = ;
  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 = ;
  78. }
  79. #pragma mark - 数据源方法
  80. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  81. {
  82. return ;
  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

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

  1. [Xcode 实际操作]一、博主领进门-(1)iOS项目的创建和项目模板的介绍

    目录:[Swift]Xcode实际操作 本文将演示iOS项目的创建和项目模板的介绍. [Create a new Xcode project]创建一个新的项目. 在弹出的模板窗口中,显示了所有的项目模 ...

  2. iOS ARC内存管理

    iOS的内存管理机制,只要是iOS开发者,不管多长的时间经验,都能说出来一点,但是要深入的理解.还是不简单的.随着ARC(自动管理内存)的流行.iOS开发者告别了手动管理内存的复杂工作.但是自动管理内 ...

  3. Unity3d:UI面板管理整合进ToLua

    本文基于 https://github.com/chiuan/TTUIFramework https://github.com/jarjin/LuaFramework_UGUI 进行的二次开发,Tha ...

  4. 理解 iOS 的内存管理

    远古时代的故事 那些经历过手工管理内存(MRC)时代的人们,一定对 iOS 开发中的内存管理记忆犹新.那个时候大约是 2010 年,国内 iOS 开发刚刚兴起,tinyfool 大叔的大名已经如雷贯耳 ...

  5. iOS10 UI教程管理层次结构

    iOS10 UI教程管理层次结构 iOS10 UI教程管理层次结构,在一个应用程序中,如果存在多个层次结构,就需要对这些层次结构进行管理.在UIView类中提供了可以用来管理层次结构的方法,让开发者可 ...

  6. [IOS]IOS UI指南

    [IOS]IOS UI指南 众所周知,IOS的界面设计,越来越流行,可以说都形成了一个标准,搜集了一些资料,供自己以后学习使用! iOS Human Interface Guidelines (中文翻 ...

  7. IOS UI 第八篇:基本UI

    实现图片的滚动,并且自动停止在每张图片上     - (void)viewDidLoad{    [super viewDidLoad]; UIScrollView *scrollView = [[U ...

  8. iOS之内存管理(ARC)

    iOS的内存管理,相信大家都不陌生,之前是使用的MRC,由开发人员手动来管理内存,后来使用了ARC,来由系统管理内存.本文主要讲讲Autorelease,Core Foundation对象在内存管理方 ...

  9. 国外IOS UI指南

    国外IOS UI指南 众所周知,IOS的界面设计,越来越流行,可以说都形成了一个标准,搜集了一些资料,供自己以后学习使用! iOS Human Interface Guidelines (中文翻译) ...

随机推荐

  1. mysql_commit() COMMIT ROLLBACK 提交 回滚 连接释放

    MySQL :: MySQL 8.0 Reference Manual :: 28.7.7.6 mysql_commit() https://dev.mysql.com/doc/refman/8.0/ ...

  2. rpyc

    import json import socket from thread import * from ansible_api import * from rpyc import Service fr ...

  3. 【开发者笔记】揣摩Spring-ioc初探,ioc是不是单例?

    前言: 控制反转(Inversion of Control,英文缩写为IoC)把创建对象的权利交给框架,是框架的重要特征,并非面向对象编程的专用术语.它包括依赖注入(Dependency Inject ...

  4. poj1177 Picture 矩形周长并

    地址:http://poj.org/problem?id=1177 题目: Picture Time Limit: 2000MS   Memory Limit: 10000K Total Submis ...

  5. Python 中的多维字典

    Python中的dict可以实现迅速查找.那么有没有像数组有二维数组一样,有二维的字典呢?比如我需要对两个关键词进行查找的时候.2D dict 可以通过 dict_2d = {'a': {'a': 1 ...

  6. Java final finally finalize有什么不同

    ① final 可以用来修饰类.方法.变量, ----final修饰的class代表不可以继承扩展 ----final的变量不可以修改 ----final的方法不可以override ----fina ...

  7. PHP多进程学习(三)__代码案例来了解父进程与子进程的执行顺序

    pcntl_fork创建子进程成功的话,系统就有了2个进程,一个为父进程,一个为子进程,父进程和子进程都继续向下执行,子进程的id号为$pid(父进程会获取子进程的$pid也就是$pid不为0,而子进 ...

  8. jQuery:$(document).ready()用法

    jQuery:$(document).ready()用法 $(document).ready() 方法允许我们在文档完全加载完后执行函数;

  9. 2018-2019-1 20189215《Linux内核原理与分析》第五周作业

    <庖丁解牛>第四章书本知识总结 系统调用的三层机制 API(应用程序编程接口) 中断向量(系统调用处理入口) 服务程序(系统调用内核处理系统) 计算机的硬件资源是有限的,为了减少有限资源的 ...

  10. Java加密代码 转换成Net版

    java版本自己封装base64 package com.qhong; import java.io.UnsupportedEncodingException; import org.apache.c ...