iOS UI-应用管理(使用Cell模板)
一、Model
- //
- // BWApp.h
- // IOS_0112_应用管理
- //
- // Created by ma c on 16/1/12.
- // Copyright (c) 2016年 博文科技. All rights reserved.
- //
- #import <Foundation/Foundation.h>
- @interface BWApp : NSObject
- @property (nonatomic, copy) NSString *size;
- @property (nonatomic, copy) NSString *download;
- @property (nonatomic, copy) NSString *name;
- @property (nonatomic, copy) NSString *icon;
- //标记是否被下载过
- @property (nonatomic, assign) BOOL isDownloaded;
- - (instancetype)initWithDict:(NSDictionary *)dict;
- + (instancetype)appWithDict:(NSDictionary *)dict;
- @end
- //
- // BWApp.m
- // IOS_0112_应用管理
- //
- // Created by ma c on 16/1/12.
- // Copyright (c) 2016年 博文科技. All rights reserved.
- //
- #import "BWApp.h"
- @implementation BWApp
- - (instancetype)initWithDict:(NSDictionary *)dict
- {
- if (self = [super init]) {
- [self setValuesForKeysWithDictionary:dict];
- }
- return self;
- }
- + (instancetype)appWithDict:(NSDictionary *)dict
- {
- return [[self alloc] initWithDict:dict];
- }
- @end
二、View
- #import <UIKit/UIKit.h>
- @class BWAppCell;
- @protocol appCellDelegate <NSObject>
- - (void)btnDownloadClick:(BWAppCell *)appCell;
- @end
- @class BWApp;
- @interface BWAppCell : UITableViewCell
- @property (nonatomic, strong) BWApp *app;
- @property (nonatomic, strong) id<appCellDelegate> delegate;
- @end
- //
- // BWAppCell.m
- // IOS_0112_应用管理
- //
- // Created by ma c on 16/1/12.
- // Copyright (c) 2016年 博文科技. All rights reserved.
- //
- #import "BWAppCell.h"
- #import "BWApp.h"
- @interface BWAppCell ()
- @property (weak, nonatomic) IBOutlet UIImageView *appIcon;
- @property (weak, nonatomic) IBOutlet UILabel *appName;
- @property (weak, nonatomic) IBOutlet UILabel *appDesc;
- @property (weak, nonatomic) IBOutlet UIButton *appDownload;
- - (IBAction)appDownload:(id)sender;
- @end
- @implementation BWAppCell
- - (void)setApp:(BWApp *)app
- {
- _app = app;
- //给子控件设置数据
- self.appIcon.image = [UIImage imageNamed:_app.icon];
- self.appName.text = _app.name;
- self.appDesc.text = [NSString stringWithFormat:@"大小:%@ | 下载量:%@",_app.size,_app.download];
- //更新下载按钮状态
- if (app.isDownloaded) {
- self.appDownload.enabled = NO;
- }
- else
- self.appDownload.enabled = YES;
- }
- #pragma mark - 下载按钮点击事件
- - (IBAction)appDownload:(id)sender {
- //1.禁用按钮
- self.appDownload.enabled = NO;
- //已经被点击过了
- self.app.isDownloaded = YES;
- if ([self.delegate respondsToSelector:@selector(btnDownloadClick:)]) {
- [self.delegate btnDownloadClick:self];
- }
- }
- - (void)awakeFromNib {
- // Initialization code
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- // Configure the view for the selected state
- }
- @end
三、Controller
- //
- // ViewController.m
- // IOS_0112_应用管理
- //
- // Created by ma c on 16/1/12.
- // Copyright (c) 2016年 博文科技. All rights reserved.
- //
- #import "ViewController.h"
- #import "BWApp.h"
- #import "BWAppCell.h"
- @interface ViewController ()<appCellDelegate>
- @property (nonatomic, strong) NSArray *appArray;
- @end
- @implementation ViewController
- #pragma mark - appCellDelegate代理方法
- - (void)btnDownloadClick:(BWAppCell *)appCell
- {
- //1.创建一个Label
- UILabel *lblMsg = [[UILabel alloc] initWithFrame:CGRectMake(, (self.view.frame.size.height - )/, , )];
- lblMsg.text = @"正在下载...";
- lblMsg.textAlignment = NSTextAlignmentCenter;
- lblMsg.backgroundColor = [UIColor blackColor];
- lblMsg.textColor = [UIColor redColor];
- //设置透明度
- lblMsg.alpha = 0.0;
- //设置圆角
- lblMsg.layer.cornerRadius = ;
- lblMsg.layer.masksToBounds = YES;
- //[self.view addSubview:lblMsg];
- [[[UIApplication sharedApplication] keyWindow] addSubview:lblMsg];
- //动画方式显示Label
- // [UIView animateWithDuration:1.0 animations:^{
- // lblMsg.alpha = 0.6;
- // }];
- [UIView animateWithDuration:1.0 animations:^{
- lblMsg.alpha = 0.6;
- } completion:^(BOOL finished) {
- //动画执行完毕以后
- //再开启一个新动画
- [UIView animateWithDuration:1.0 delay:0.5 options:UIViewAnimationOptionCurveLinear animations:^{
- lblMsg.alpha = ;
- } completion:^(BOOL finished) {
- [lblMsg removeFromSuperview];
- }];
- }];
- }
- #pragma mark - 懒加载
- - (NSArray *)appArray
- {
- if (_appArray == nil) {
- NSString *path = [[NSBundle mainBundle] pathForResource:@"apps_full.plist" ofType:nil];
- NSArray *arrDict = [NSArray arrayWithContentsOfFile:path];
- NSMutableArray *arrModel = [NSMutableArray array];
- for (NSDictionary *dict in arrDict) {
- BWApp *app = [BWApp appWithDict:dict];
- [arrModel addObject:app];
- }
- _appArray = arrModel;
- }
- return _appArray;
- }
- #pragma mark - viewDidLoad
- - (void)viewDidLoad {
- [super viewDidLoad];
- //NSLog(@"%@",self.appArray);
- self.tableView.rowHeight = ;
- }
- #pragma mark - 数据源方法
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return ;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return self.appArray.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- //1.获取数据模型
- BWApp *model = self.appArray[indexPath.row];
- //2.通过storyboard中cell模板创建单元格
- static NSString *ID = @"app_cell";
- BWAppCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
- //3.设置数据
- cell.app = model;
- cell.delegate = self;
- //4.返回数据
- return cell;
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- @end
iOS UI-应用管理(使用Cell模板)的更多相关文章
- [Xcode 实际操作]一、博主领进门-(1)iOS项目的创建和项目模板的介绍
目录:[Swift]Xcode实际操作 本文将演示iOS项目的创建和项目模板的介绍. [Create a new Xcode project]创建一个新的项目. 在弹出的模板窗口中,显示了所有的项目模 ...
- iOS ARC内存管理
iOS的内存管理机制,只要是iOS开发者,不管多长的时间经验,都能说出来一点,但是要深入的理解.还是不简单的.随着ARC(自动管理内存)的流行.iOS开发者告别了手动管理内存的复杂工作.但是自动管理内 ...
- Unity3d:UI面板管理整合进ToLua
本文基于 https://github.com/chiuan/TTUIFramework https://github.com/jarjin/LuaFramework_UGUI 进行的二次开发,Tha ...
- 理解 iOS 的内存管理
远古时代的故事 那些经历过手工管理内存(MRC)时代的人们,一定对 iOS 开发中的内存管理记忆犹新.那个时候大约是 2010 年,国内 iOS 开发刚刚兴起,tinyfool 大叔的大名已经如雷贯耳 ...
- iOS10 UI教程管理层次结构
iOS10 UI教程管理层次结构 iOS10 UI教程管理层次结构,在一个应用程序中,如果存在多个层次结构,就需要对这些层次结构进行管理.在UIView类中提供了可以用来管理层次结构的方法,让开发者可 ...
- [IOS]IOS UI指南
[IOS]IOS UI指南 众所周知,IOS的界面设计,越来越流行,可以说都形成了一个标准,搜集了一些资料,供自己以后学习使用! iOS Human Interface Guidelines (中文翻 ...
- IOS UI 第八篇:基本UI
实现图片的滚动,并且自动停止在每张图片上 - (void)viewDidLoad{ [super viewDidLoad]; UIScrollView *scrollView = [[U ...
- iOS之内存管理(ARC)
iOS的内存管理,相信大家都不陌生,之前是使用的MRC,由开发人员手动来管理内存,后来使用了ARC,来由系统管理内存.本文主要讲讲Autorelease,Core Foundation对象在内存管理方 ...
- 国外IOS UI指南
国外IOS UI指南 众所周知,IOS的界面设计,越来越流行,可以说都形成了一个标准,搜集了一些资料,供自己以后学习使用! iOS Human Interface Guidelines (中文翻译) ...
随机推荐
- mysql_commit() COMMIT ROLLBACK 提交 回滚 连接释放
MySQL :: MySQL 8.0 Reference Manual :: 28.7.7.6 mysql_commit() https://dev.mysql.com/doc/refman/8.0/ ...
- rpyc
import json import socket from thread import * from ansible_api import * from rpyc import Service fr ...
- 【开发者笔记】揣摩Spring-ioc初探,ioc是不是单例?
前言: 控制反转(Inversion of Control,英文缩写为IoC)把创建对象的权利交给框架,是框架的重要特征,并非面向对象编程的专用术语.它包括依赖注入(Dependency Inject ...
- poj1177 Picture 矩形周长并
地址:http://poj.org/problem?id=1177 题目: Picture Time Limit: 2000MS Memory Limit: 10000K Total Submis ...
- Python 中的多维字典
Python中的dict可以实现迅速查找.那么有没有像数组有二维数组一样,有二维的字典呢?比如我需要对两个关键词进行查找的时候.2D dict 可以通过 dict_2d = {'a': {'a': 1 ...
- Java final finally finalize有什么不同
① final 可以用来修饰类.方法.变量, ----final修饰的class代表不可以继承扩展 ----final的变量不可以修改 ----final的方法不可以override ----fina ...
- PHP多进程学习(三)__代码案例来了解父进程与子进程的执行顺序
pcntl_fork创建子进程成功的话,系统就有了2个进程,一个为父进程,一个为子进程,父进程和子进程都继续向下执行,子进程的id号为$pid(父进程会获取子进程的$pid也就是$pid不为0,而子进 ...
- jQuery:$(document).ready()用法
jQuery:$(document).ready()用法 $(document).ready() 方法允许我们在文档完全加载完后执行函数;
- 2018-2019-1 20189215《Linux内核原理与分析》第五周作业
<庖丁解牛>第四章书本知识总结 系统调用的三层机制 API(应用程序编程接口) 中断向量(系统调用处理入口) 服务程序(系统调用内核处理系统) 计算机的硬件资源是有限的,为了减少有限资源的 ...
- Java加密代码 转换成Net版
java版本自己封装base64 package com.qhong; import java.io.UnsupportedEncodingException; import org.apache.c ...