一些协议
//
// XZEquipmentCellModel.h
// XingZhang
//
// Created by 孟辉 on 2018/11/8.
// Copyright © 2018 xz. All rights reserved.
//
#import <Foundation/Foundation.h>
//@class XZEquipmentUser;
//@class XZEquipmentRelate;
@class XZLinkInfo;
@class topicItem;
typedef enum : NSUInteger {
XZEquipmentCellTypeBanner = 0, /** 广告条 */
XZEquipmentCellTypeIssues = 1, /** 话题 */
XZEquipmentCellTypeHaedline = 2, /** 官方资讯 */
XZEquipmentCellTypeFeatured = 3, /** 精选 */
XZEquipmentCellTypeMoreImages = 4, /** 九宫格图片 */
XZEquipmentCellTypeVideo = 5, /** 视频 */
XZEquipmentCellTypeUnknow = 6, /** 数据异常 如状态是视频但是没有视频附件的 如状态是图片但是没有图片附件的*/
} XZEquipmentCellType;
NS_ASSUME_NONNULL_BEGIN
/*
装备圈基础协议
*/
@protocol XZEquipmentCellBaseDataSource <NSObject>
@property (nonatomic,assign)XZEquipmentCellType cellType;
@end
/*
装备圈 广告条协议
*/
@protocol XZEquipmentBannerCellDataSource <XZEquipmentCellBaseDataSource>
@end
/*
装备圈 广告条协议
*/
@protocol XZEquipmentHaedlineCellDataSource <XZEquipmentCellBaseDataSource>
@end
/*
装备圈 精选 协议
*/
@protocol XZEquipmentIssuesCellDataSource <XZEquipmentCellBaseDataSource>
@end
/*
装备圈话题协议
*/
@protocol XZEquipmentFeaturedCellDataSource <XZEquipmentCellBaseDataSource>
@end
/*
装备圈装备发布者协议
*/
@protocol XZEquipmentUserCellDataSource <NSObject>
@property (nonatomic,strong) NSString *headPortrait;
//用户
@property (nonatomic,strong) NSString *name;
@property (nonatomic,strong) NSString *levelName;
@end
/*
装备圈装备 相关的 协议: 点赞数 分享数 下载数
*/
@protocol XZEquipmentRelateCellDataSource <NSObject>
//下载量
@property (nonatomic,assign) NSInteger downloadCount;
//分享量
@property (nonatomic,assign) NSInteger shareCount;
//关注状态 1已关注 0未关注
@property (nonatomic,assign)BOOL careStatus;
@end
/*
装备圈装备协议 继承多个接口 装备的一个功能就是一个协议
*/
@protocol XZEquipmentCellDataSource <XZEquipmentUserCellDataSource,XZEquipmentRelateCellDataSource,XZEquipmentCellBaseDataSource>
//
@property (nonatomic,strong) NSString *articleId;
//推荐描述
@property (nonatomic,strong) NSString *recommendDesc;
//推荐描述
@property (nonatomic,strong) NSString *articleDesc;
//商品附件
@property (nonatomic,strong) XZLinkInfo *linkInfo;
//1图片 2视频
@property (nonatomic,assign) NSInteger mediaType;
//多媒体附件
@property (nonatomic,strong) NSArray<topicItem *> * topicList;
@end
/*
装备视频的协议
*/
@protocol XZEquipmentVideoCellDataSource <XZEquipmentCellDataSource>
//视频链接
@property (nonatomic,strong) NSString *videoUrl;
//视频主题
@property (nonatomic,strong) NSString *videoImageUrl;
@end
/*
装备图片的协议
*/
@protocol XZEquipmentMoreIamgesCellDataSource <XZEquipmentCellDataSource>
//图片链接
@property (nonatomic,strong) NSString *videoUrl;
@property (nonatomic,strong) NSArray<NSString *> *imageUrls;
@end
@interface XZEquipmentCellModel : NSObject
@end
/*
@interface XZEquipmentUser : NSObject
@end
@interface XZEquipmentRelate : NSObject
@end
*/
NS_ASSUME_NONNULL_END
独立业务
滚动广告
@interface XZEquipmentBannerCell : UITableViewCell
- (void)configCell:(id<XZEquipmentBannerCellDataSource>)model;
@end
话题
@interface XZEquipmetIssuesCell : UITableViewCell
- (void)configCell:(id<XZEquipmentIssuesCellDataSource>)model;
@end
装备精选
@interface XZEquipmetFeaturedCell : UITableViewCell
- (void)configCell:(id<XZEquipmentFeaturedCellDataSource>)model;
@end
装备头条新闻
@interface XZEquipmetHaedlineCell : UITableViewCell
- (void)configCell:(id<XZEquipmentHaedlineCellDataSource>)model;
@end
九宫格图片
@interface XZEquipmetMoreImagesCell : UITableViewCell
- (void)configCell:(id<XZEquipmentCellDataSource>)model;
@end
视频
@interface XZEquipmetVideoCell : UITableViewCell
- (void)configCell:(id<XZEquipmentCellDataSource>)model;
@end
controller的组装 组件
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
//数据源
return self.dataArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
XZEquipment *equipment = self.dataArray[indexPath.row];
//如果装备样式未知 不用f计算高度
if (equipment.cellType == XZEquipmentCellTypeUnknow) {
return CGFLOAT_MIN;
}
//正确则 自动动态布局高度
return UITableViewAutomaticDimension;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//没有接口按顺序各个组件都呈现一个
XZEquipmentCellType cellType = indexPath.row;
switch (cellType) {
case XZEquipmentCellTypeBanner: /** 广告条 */
{
XZEquipmentBannerCell *cell = (XZEquipmentBannerCell *)[XZEquipmentBannerCell cellGetTableView:tableView];
//赋值
[cell configCell:self.dataArray[indexPath.row]];
return cell;
}
case XZEquipmentCellTypeIssues: /** 话题 */
{
XZEquipmetIssuesCell *cell = (XZEquipmetIssuesCell *)[XZEquipmetIssuesCell cellGetTableView:tableView];
[cell configCell:self.dataArray[indexPath.row]];
return cell;
}
case XZEquipmentCellTypeHaedline: /** 官方资讯 */
{
XZEquipmetHaedlineCell *cell = (XZEquipmetHaedlineCell *)[XZEquipmetHaedlineCell cellGetTableView:tableView];
return cell;
}
case XZEquipmentCellTypeFeatured: /** 精选 */
{
XZEquipmetFeaturedCell *cell = (XZEquipmetFeaturedCell *)[XZEquipmetFeaturedCell cellGetTableView:tableView];
return cell;
}
case XZEquipmentCellTypeMoreImages: /** 九宫格图片 */
{
XZEquipmetMoreImagesCell *cell = (XZEquipmetMoreImagesCell *)[XZEquipmetMoreImagesCell cellGetTableView:tableView];
return cell;
}
case XZEquipmentCellTypeVideo: /** 视频 */
{
XZEquipmetVideoCell *cell = (XZEquipmetVideoCell *)[XZEquipmetVideoCell cellGetTableView:tableView];
return cell;
}
default:{
// 未知 则返回一个空的高度为0 的cell
UITableViewCell *cell = [UITableViewCell cellGetTableView:self.tableView];
return cell;
}
}
}