组件化
组件化

如今实现的方案

业务业务之间沟通
-
解决业务与业务之间页面跳转,
路由,或者业务manger的别名 -
解决业务与业务之后cellview展示的穿插
1.cell数据实现统一刷新接口,data建议统一字典类型,内部在使用时,自己做对应的数据转化,模型及其它- (void)xhl_refreshData:(id _Nonnull )data;
2.自己实现一个manger管理cell如下的方法 然后返回统一的接口
//需要根据数据做一个展示,请返回我cell名字,高度,以及data模型,情在cell中 - (void)xhl_refreshData:(id _Nonnull )data; 方法中实现自己的数据解析,data就是你传入的数据 + (XhlItemModel *)xhl_newsCellData:(NSDictionary *)dict; //需要在新闻列表展示的类型cell + (NSArray *)xhl_newsRegisterClass;
3.点击事件处理统一走路由的XhlMail://newDatil
4.列表可以实现,模型套模型的方案实现展示,模型中data,就是自己的data,cell高度,是自己模型中计算好了,给展示模型,cell名字可以根据不同类型进行配置
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{ return self.dataArry.count; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ return self.dataArry[section].count; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ CQItemModel *model = self.dataArry[indexPath.section][indexPath.row]; UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:model.cellName forIndexPath:indexPath]; [cell cq_refreshData:model.data]; return cell; } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{ CQItemModel *model = self.dataArry[indexPath.section][indexPath.row]; return model.sizeForItem; } - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{ CQItemModel *model = self.dataArry[section].firstObject; return model.insetForSection; } - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{ CQItemModel *model = self.dataArry[section].firstObject; return model.minimumLineSpacing; } //区头高度 - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section{ CQItemModel *model = self.dataArry[section].firstObject; return model.footViewSize; } - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{ CQItemModel *model = self.dataArry[section].firstObject; return model.minimumInteritemSpacing; }
数据组装
CQItemModel *topUp = [[CQItemModel alloc] init];
topUp.cellName = @"CQDgShopRecCell";
topUp.sizeForItem = CGSizeMake((SCREEN_WIDTH)/2, height);
topUp.footViewSize = CGSizeMake(SCREEN_WIDTH, 15);
for (CQDgHomeConfigModel *model in self.configArry) {
if ([model.type isEqualToString:@"5"]) {
topUp.data = model;
break;
}
}
[self.dataArry addObject:@[wishTree,topUp]];
- 业务与业务之间网络地址,appId通信
每个业务配置一套属于自己的网络地址,和appId、host
在业务通过路由调用自己时,实现网络地址和appId切换,没有默认app全局设置
app与业务之间的沟通
- 业务适配app(颜色,UI,数据,图片,网络地址)
- 沟通方式
1.直接导入头文件,业务的manger
2.也可以通过manger的别名使用
业务manger的别名处理方案
所有的manger写的都是类方法,或者单例方法,可以通过导入manger的头文件方式之间使用,由于,业务业务之间沟通导入头文件.,那么必然会有m,文件关联,m文件会有业务关联,有可能在自己做的业务中没有这个业务.那么就没法使用了.
那么不导入头文件,就可以导入一个api文件,不存在m文件,这样一个文件,协议可以实现.只有方法名,没有实现文件.
/*
* 账号协议,该协议只在内部调用
*/
@protocol XHLLoginProtocol <XHLBaseProtocol>
@optional
/**
* @brief 调用登录接口
* @param loginCompletionBlock 不能设置为nil 登录成功、失败(退出登录页面)的回调,参数YES:登录成功,NO:登录失败或者未登录直接退出登录页面;必须要调用,不然会导致再次登录无法调起
*/
+ (void)xhlLogin:(void (^)(BOOL success))loginCompletionBlock;
//退出登录
+ (void)logout;
/**
登录成功通知回调
*/
+ (NSString *)notificationLoginSuccess;
/**
登录状态变化通知回调
*/
+ (NSString *)notificationLoginStateChange;
/**
退出登录成功通知回调
*/
+ (NSString *)notificationLogout;
@end
如过通过这个协议文文件找到一个实现文件的类,那么就可以调用.
XhlPyramid 实现了这个方案
首先给XhlPyramid声明一个分类,然后里面实现一个查找自己实现类的方法,方便使用XhlPyramid打点调用

然后对实现类进行注册,关联协议类,和实现类
[XhlPyramid registerService:XHLLoginProtocol implClass:XhlLoginManger];\协议管理实现类
[XhlPyramid registerAlias:@selector(Alias) forService:XHLLoginProtocol];\协议管理别名
内部是使用的一个字典来关联


//别名关联协议字典

当你使用,XhlPyramid.Logind的时候,+ (Class<XHLLoginProtocol>)xhl_login;不存在,内部使用消息转发机制,为他添加一个方法,实现查找,在已经存好的字典中进行查找,最后返回一个对象

存在问题
协议中间调度器,是不支持,一个协议关联多个类,还是我没有研究透,
别名管理协议,在协议中就可以实现,为什么还要,在实现类中实现