IOS设计模式之一(MVC模式,单例模式)

- @property (nonatomic, copy, readonly) NSString *title, *artist, *genre, *coverUrl, *year;
- - (id)initWithTitle:(NSString*)title artist:(NSString*)artist coverUrl:(NSString*)coverUrl year:(NSString*)year;
- - (id)initWithTitle:(NSString*)title artist:(NSString*)artist coverUrl:(NSString*)coverUrl
- year:(NSString*)year {
- self = [super init];
- if (self)
- {
- _title = title;
- _artist = artist;
- _coverUrl = coverUrl;
- _year = year;
- _genre = @"Pop";
- }
- return self;
- }
- - (id)initWithFrame:(CGRect)frame albumCover:(NSString*)albumCover;
- @implementationAlbumView
- {
- UIImageView *coverImage;
- UIActivityIndicatorView *indicator;
- }
- - (id)initWithFrame:(CGRect)frame albumCover:(NSString*)albumCover
- {
- self = [super initWithFrame:frame];
- if (self)
- {
- self.backgroundColor = [UIColor blackColor];
- // the coverImage has a 5 pixels margin from its frame
- coverImage = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, frame.size.width-10,
- frame.size.height-10)];
- [self addSubview:coverImage];
- indicator = [[UIActivityIndicatorView alloc] init];
- indicator.center = self.center;
- indicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
- [indicator startAnimating];
- [self addSubview:indicator];
- }
- return self;
- }
- @end




- @interfaceLibraryAPI : NSObject
- + (LibraryAPI*)sharedInstance;
- @end
- + (LibraryAPI*)sharedInstance
- {
- // 1
- static LibraryAPI *_sharedInstance = nil;
- // 2
- static dispatch_once_t oncePredicate;
- // 3
- dispatch_once(&oncePredicate, ^{
- _sharedInstance = [[LibraryAPI alloc] init];
- });
- return _sharedInstance;
- }
- - (NSArray*)getAlbums;
- - (void)addAlbum:(Album*)album atIndex:(int)index;
- - (void)deleteAlbumAtIndex:(int)index;
- @interfacePersistencyManager () {
- // an array of all albums
- NSMutableArray *albums;
- }
- - (id)init
- {
- self = [super init];
- if (self) {
- // a dummy list of albums
- albums = [NSMutableArrayarrayWithArray:
- @[[[Album alloc] initWithTitle:@"Best of Bowie" artist:@"David Bowie" coverUrl:@"http://www.coversproject.com/static/thumbs/album/album_david%20bowie_best%20of%20bowie.png" year:@"1992"],
- [[Album alloc] initWithTitle:@"It's My Life" artist:@"No Doubt" coverUrl:@"http://www.coversproject.com/static/thumbs/album/album_no%20doubt_its%20my%20life%20%20bathwater.png" year:@"2003"],
- [[Album alloc] initWithTitle:@"Nothing Like The Sun" artist:@"Sting" coverUrl:@"http://www.coversproject.com/static/thumbs/album/album_sting_nothing%20like%20the%20sun.png" year:@"1999"],
- [[Album alloc] initWithTitle:@"Staring at the Sun" artist:@"U2" coverUrl:@"http://www.coversproject.com/static/thumbs/album/album_u2_staring%20at%20the%20sun.png" year:@"2000"],
- [[Album alloc] initWithTitle:@"American Pie" artist:@"Madonna" coverUrl:@"http://www.coversproject.com/static/thumbs/album/album_madonna_american%20pie.png" year:@"2000"]]];
- }
- return self;
- }
- - (NSArray*)getAlbums
- {
- return albums;
- }
- - (void)addAlbum:(Album*)album atIndex:(int)index
- {
- if (albums.count >= index)
- [albums insertObject:album atIndex:index];
- else
- [albums addObject:album];
- }
- - (void)deleteAlbumAtIndex:(int)index
- {
- [albums removeObjectAtIndex:index];
- }
IOS设计模式之一(MVC模式,单例模式)的更多相关文章
- iOS 设计模式之工厂模式
iOS 设计模式之工厂模式 分类: 设计模式2014-02-10 18:05 11020人阅读 评论(2) 收藏 举报 ios设计模式 工厂模式我的理解是:他就是为了创建对象的 创建对象的时候,我们一 ...
- Android 设计模式之MVC模式
说到Android设计模式的MVC模式,估计很多人都是比较熟悉了,这里深入了解一下MVC到底是怎么回事,以ListView为例子讲解. 一.深入理解MVC概念 MVC即Model-View-Contr ...
- python 设计模式之MVC模式
一.简单介绍 mvc模式 the model-view-controller pattern mvc模式是一个运用在软件工程中的设计模式.mvc模式脱离了以前简单的web服务设计逻辑,将开发,测试 ...
- Python设计模式之MVC模式
# -*- coding: utf-8 -*- # author:baoshan quotes = ('A man is not complete until he is married. Then ...
- iOS:使用MVC模式帮ViewController瘦身
如何给UIViewController瘦身 随着程序逻辑复杂度的提高,你是否也发现了App中一些ViewController的代码行数急剧增多,达到了2,3千行,甚至更多.这时如果想再添加一点功能或者 ...
- 设计模式-14 MVC模式
一 MVC设计模式 MVC 模式代表 Model-View-Controller(模型-视图-控制器) 模式,它是一个存在于服务器 表达层的模型,它将应用分开,改变应用之间的高度耦合 MVC设计模式将 ...
- 【设计模式】MVC模式
MVC 模式代表 Model-View-Controller(模型-视图-控制器) 模式.这种模式用于应用程序的分层开发. Model(模型) - 模型代表一个存取数据的对象或 JAVA POJO.它 ...
- python的设计模式之MVC模式
模型-视图-控制器模式 关注点分离(Separation of Concerns,SoC)原则是软件工程相关的设计原则之一.SoC原则背后的思想是将一个应用切分成不同的部分,每个部分解决一个单独的关注 ...
- iOS架构入门 - MVC模式实例演示
MVC模式的目的是实现一种动态的程序设计,使后续对程序的修改和扩展简化,并且使程序某一部分的重复利用成为可能.除此之外,此模式通过对复杂度的简化,使程序结构更加直观 控制器(Controller)-- ...
- iOS通用的MVC模式项目框架MobileProject
最近项目比较不赶的情况下,决定把一些通用.常用的内容集成在一个项目框架中,意在新项目中可以快速搭建:其实经过几个项目后,总是有一些重复的创建工作,可以使用本项目的内容直接进行开发:采用的是MVC的分层 ...
随机推荐
- Oracle游标总结三
-- 声明游标:CURSOR cursor_name IS select_statement --For 循环游标--(1)定义游标--(2)定义游标变量--(3)使用for循环来使用这个游标,for ...
- 转一篇 adaboost 的好文 AdaBoost简介及训练误差分析
AdaBoost简介及训练误差分析 http://wenku.baidu.com/link?url=y9Q2qjrJr6IShyY5EQEmvkPZmmP4t3HOdHUgMWaIffI9W0uzTr ...
- switch结构2016/03/08
Switch 03/08 一.结构 switch(){ case *: ;break;……default: ;brek;} 练习:输入一个日期,判断这一年第几天? Console.Write(&q ...
- $.trim()函数
$.trim(str) 返回:string: 参数str :String类型,需要去除两端空白字符的字符串.如果参数str不是字符串类型,该函数将自动将其转为字符串(一般调用其toString()方法 ...
- (function($){...})(jQuery) 函数详解
function(arg){...} 这是一个匿名函数,参数是arg. 而调用匿名函数时,是在函数后面写上括号和实参的,由于操作符的优先级,函数本身也需要用括号,即: function(arg){.. ...
- OpenStack 虚拟机监控方案确定
Contents [hide] 1 监控方案调研过程 1.1 1. 虚拟机里内置监控模块 1.2 2. 通过libvirt获取虚拟机数据监控. 2 a.测试openstack的自待组件ceilomet ...
- Awk使用一例:获取ASCII可见字符
要做一个需求, 支持可见特殊字符的密码设置. 首先, 需要获取到所有可见特殊字符. 到网上搜索到 ASCII 字符表格, 并复制到文本文件 vschars.txt: 00 00 0 nul 100 4 ...
- ubuntu安装最新版本的node.js
下面的方法适用于最新版本的Ubuntu.Ubuntu 12.04 LTS.Ubuntu 12.10.Ubuntu 13.04等版本.它可以帮助开发者在Ubuntu上安装Node.js,无需从头编译安装 ...
- ecshop增加pc扫描二维码微信支付功能代码
ecshop开发网站,如果没有手机版,又想通过微信支付,可以加入pc二维码扫描微信支付功能 工具/原料 ecshop商城系统,phpqrcode,WxPayPubHelper 公众号已申请微信支付 方 ...
- 收藏本网站兼容火狐IE
<script type="text/javascript"> function AddFavorite(sURL, sTitle) {try { window.ext ...