IOS——TableView 中利用Item模型进行 Cell 的开发(2)Item 模型篇
来源:互联网 发布:h3c stp 阻塞端口 编辑:程序博客网 时间:2024/06/08 18:24
不知不觉过了这么多天了,作者真的是忙的透不过气了,新应用猪猪刚放上 APPStore,后脚转吧应用有更新大版本,累到在地了。。好了,废话不多说,给大家继续我们的 TableView利用 Item 模型开发的第2编了,相信大家都看过作者的第一篇了,第一篇主要讲父类 TableView 里面的创建,那么 Item 模型怎么创建呢
当然第一步,我们要有一个父类的 Item,也就是上一篇在文章中多次出现的 BaseItem 了
#import <Foundation/Foundation.h>typedef void(^BaseItemOption)();@interface BaseItem : NSObject// 这个属性是用来标志 Item 类型,告诉系统,我们要创建哪一种 cell@property (nonatomic,assign) ItemType itemType;// 这个属性是 block 属性,用来放置一个预防操作的@property (nonatomic,copy) BaseItemOption option; // 因为许许多多的 cell 都会用到标题图片这两个属性,所以特意在父类先添加了@property (nonatomic,copy) NSString *title; // 标题@property (nonatomic,copy) NSString *icon; // 图片 // 用来选择点击样式,如果为 Yes,则cell 的selectionStyle为UITableViewCellSelectionStyleNone@property (nonatomic,assign) BOOL NotEnable;// 用来返回cell的高度@property (nonatomic,assign) CGFloat height; // 工厂方法,快速创建 cell+ (instancetype)itemWithTitle:(NSString *)title icon:(NSString *)icon type:(ItemType)type;
#import "BaseItem.h"@implementation BaseItem+ (instancetype)itemWithTitle:(NSString *)title icon:(NSString *)icon type:(ItemType)type{// 这里一定要用[[self alloc]init],因为 其子类运用父类方法的时候,self 能识别出子类的真实类型 BaseItem *item = [[self alloc]init]; item.title = [title copy]; item.icon = [icon copy]; item.itemType = type; return item;}@end
好了,父类的 item 我们已经创建好了,那么,我们现在来个简单的例子,就是我们常见的这种样式了,如下图
以下我们就叫这种 cell 为 ArrowItem,因为每点击一个这样的 Item 都会调到不同的控制器。
那么这个 ArrowItem 内部是怎么个神奇呢,能一句代码就创建?那么我们就看看ArrowItem里面究竟有什么东西
#import "BaseItem.h"@interface FSArrowItem : BaseItem// 需要跳转到的控制器的类@property (nonatomic,assign) Class desveClass;/** 是否需要判断用户是否已经登录,如果未登录,则跳到登录界面*/@property (nonatomic,assign) BOOL judge;+ (instancetype)itemWithTitle:(NSString *)title icon:(NSString *)icon desveClass:(Class)desveClass isJudgeLogin:(BOOL )judge itemType:(ItemType)type;@end
#import "FSArrowItem.h"@implementation FSArrowItem+ (instancetype)itemWithTitle:(NSString *)title icon:(NSString *)icon desveClass:(Class)desveClass isJudgeLogin:(BOOL )judge itemType:(ItemType)type{ FSArrowItem *item = [super itemWithTitle:title icon:icon type:type]; item.desveClass = desveClass; item.judge = judge; return item;}@end
哈哈,相信大家也知道,这是个标准的模型了,那么当然是很简单的模型了呀。
到这里,如果有经验的朋友相信结合第一篇的博客就已经大概能猜出作者想要表达的是什么了,那么我们继续说,这么简简单单的一个模型用起来复杂么那么,作者就用项目的一句源代码告诉大家
- (void)buildUI{ FSArrowItem *phtots = [FSArrowItem itemWithTitle:@"相册" icon:@"FS_Profile_Photo" desveClass:[FSDynamicViewController class] isJudgeLogin:YES itemType:ItemTypeArrow]; BaseItem *collect = [FSArrowItem itemWithTitle:@"收藏" icon:@"FS_Profile_Collection" desveClass:[FSCollectionViewController class] isJudgeLogin:YES itemType:ItemTypeArrow]; self.messageItem = [FSArrowItem itemWithTitle:@"消息" icon:@"FS_Profile_Message" desveClass:[FSProfileMessageViewController class] isJudgeLogin:YES itemType:ItemTypeArrow]; BaseItem *grade = [FSArrowItem itemWithTitle:@"积分" icon:@"FS_Profile_Grade" desveClass:[FSPointViewController class] isJudgeLogin:YES itemType:ItemTypeArrow]; BaseItem *system = [FSArrowItem itemWithTitle:@"系统设置" icon:@"FS_Profile_System" desveClass:[FSSystemViewController class] isJudgeLogin:NO itemType:ItemTypeArrow]; NSArray *group0 = @[phtots,collect,self.messageItem,grade,system]; [self.dataSource addObject:group0];}
好了,就这么简单几句代码就把上图创建好了,没错,就是这么几句代码,说好的一句一个 cell 嘛,那么 cell 的内部要怎么实现呢?这就是我们下一篇博客的内容了,今天就先到这里啦,如果喜欢我们朋友可以关注一下我,明天继续我们的《TableView 中利用Item模型进行 Cell 的开发(3)TableViewCell 篇》
以上图片为新应用猪猪的截图,喜欢的朋友可以来下面这个链接下载http://pre.im/3a15,但是这个应用还在审核中,所以搞了个内测版让大家先尝尝鲜,等正式出来了,各位就可以下载了,完全个人独立开发的项目喔,么么哒
- IOS——TableView 中利用Item模型进行 Cell 的开发(2)Item 模型篇
- IOS——TableView 中利用Item模型进行 Cell 的开发(1)TableView 篇
- IOS开发 tableview中cell的用法
- IOS开发 tableview中cell的用法
- IOS开发 tableview中cell的用法
- IOS开发 tableview中cell的用法
- 该篇博客是在《iOS高级开发——CollectionView的动态增删cell及模型重构》的基础上继续进行开发的。在之前那篇博客中,我们实现了动态的增删cell,并且使用了模型Model进行重构
- ios中自定义cell即列表的item
- iOS 开发中移动collectionView的item
- iOS高级开发——CollectionView的动态增删cell及模型重构
- iOS高级开发——CollectionView修改cell的文本及模型重构
- 怎样在ios开发中设置tableview的cell颜色
- iOS开发,tableView中cell的重用详解
- iOS开发,删除tableView的cell
- TableView 设置Item的位置
- iOS开发UI篇—自定义瀑布流控件(cell的循环利用)
- IOS中TableView的cell显示问题
- IOS中点击TableView的Cell跳转
- HDU 5015 矩阵快速幂
- Linux根文件系统构建
- C语言字符串总结
- 常用的基本控件TextView、富文本和RadioButton
- FOUNDATION
- IOS——TableView 中利用Item模型进行 Cell 的开发(2)Item 模型篇
- 三星应用商店注册的二进制 不符合 GALAXY Specials 的类别条件解决办法
- OpenCV 谈opencv的长处与短处:模板匹配,金字塔
- url中中文转化
- 关于动作融合的一些通俗理解
- “完全背包”详解及实现(包含背包具体物品的求解)
- 九度 oj 1125
- Machine Learning “for Dummies” (part 2)
- Bug模式之写入的数据格式出错