imitate wechat - 5
来源:互联网 发布:网络歌手易言照片 编辑:程序博客网 时间:2024/06/05 00:51
在这里分析上两篇实现中一些技巧的东西:
1.随处可以见的善用set方法置数据:
在ChartCell中定义了ChartCellFrame这个属性:
@property (nonatomic, strong)ChartCellFrame* cellFrame;
- (void)setCellFrame:(ChartCellFrame *)cellFrame{ _cellFrame = cellFrame; ChartMessage* chartMessage = cellFrame.chartMessage; self.icon.frame = cellFrame.iconRect; self.icon.image = [UIImage imageNamed:(NSString*)chartMessage.icon]; self.chartView.chartMessage = chartMessage; self.chartView.frame = cellFrame.chartViewRect; [self setBackGroundImageViewImage:self.chartView from:@"chatfrom_bg_normal.png" to:@"chatto_bg_normal.png"]; self.chartView.contentLabel.text = chartMessage.content;}
但在setCellFrame这个方法里面却同时设置了别的东西,这里是对ChartMessage的设置。
同理:ChartCellFrame类里面定义的ChartMessage也是这样操作。
总结:
优点:这样做的好处是大大减少了初始化initWith的时候的方法设置的复杂程度,我们可以在init初始化的时候常常会顺带地设置很多相关的东西,这样的setFrame可以归类地设置相关的东西。
缺点:很多属性的设置被分散化,碎片化,这样的话,增加我们如何设置才是最优的方法的难度。本质上和init里面设置是一样的效果。
2.善用代理,并且“嵌套”使用
我们来看看这里使用到的两个委托:
ChartContentViewDelegate 的定义和实现:
#import <Foundation/Foundation.h>@class ChartContentView, ChartMessage;@protocol ChartContentViewDelegate <NSObject>- (void)chartContentViewLongPress:(ChartContentView *)chartView content:(NSString *)content;- (void)chartContentViewTapPress:(ChartContentView *)chartView content:(NSString *)content;@end
@interface ChartCell ()<ChartContentViewDelegate>@end- (void)chartContentViewTapPress:(ChartContentView *)chartView content:(NSString *)content{ if ([self.delegate respondsToSelector:@selector(chartCell:tapContent:)]) { [self.delegate chartCell:self tapContent:content]; }}
ChartCellDelegate的定义和实现:
#import <UIKit/UIKit.h>@class ChartCell;@protocol ChartCellDelegate <NSObject>- (void)chartCell:(ChartCell *)chartCell tapContent:(NSString *)content;@end
视图控制器里面实现的委托方法:
#pragma mark - ChartCellDelegate- (void)chartCell:(ChartCell *)chartCell tapContent:(NSString *)content{ NSLog(@" Nest Delegate .");}
这样隔一层的实现使得面相对象的层次感,类的功能任务所属更加明确!
3.面相对象的类的划分明确:
MVC这个模式在这个实现中非常明晰,用上一节的图可以很清楚地表现出来:
0 0
- imitate wechat - 5
- imitate wechat - 0
- imitate wechat - 1
- imitate wechat - 2
- imitate wechat - 3
- imitate wechat - 4
- Imitate click
- css style imitate winXp
- css3-clip-path-imitate
- WeChat开发
- wechat-day1
- weChat开发
- 模拟WeChat
- Saltstack
- 统计思维:程序员数学之概率统计(第2版)——互动出版网
- PowerOff 定时关机软件
- Android 发通知NotificationManager和Notification的详解
- JavaScript 选择input光标所在位置 设置input的内容选中并得到选中的值
- imitate wechat - 5
- prev_permutation
- Python 元编程
- face++的颜值计算算法实现
- Javascript的setTimeOut和setInterval用法
- python下载图片
- 使用指向函数的指针
- pop 跳转
- 图形用户界面:通过ip获取地址并显示天气情况