一些協(xié)議
//
// 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, /** 數(shù)據(jù)異常 如狀態(tài)是視頻但是沒(méi)有視頻附件的 如狀態(tài)是圖片但是沒(méi)有圖片附件的*/
} XZEquipmentCellType;
NS_ASSUME_NONNULL_BEGIN
/*
裝備圈基礎(chǔ)協(xié)議
*/
@protocol XZEquipmentCellBaseDataSource <NSObject>
@property (nonatomic,assign)XZEquipmentCellType cellType;
@end
/*
裝備圈 廣告條協(xié)議
*/
@protocol XZEquipmentBannerCellDataSource <XZEquipmentCellBaseDataSource>
@end
/*
裝備圈 廣告條協(xié)議
*/
@protocol XZEquipmentHaedlineCellDataSource <XZEquipmentCellBaseDataSource>
@end
/*
裝備圈 精選 協(xié)議
*/
@protocol XZEquipmentIssuesCellDataSource <XZEquipmentCellBaseDataSource>
@end
/*
裝備圈話題協(xié)議
*/
@protocol XZEquipmentFeaturedCellDataSource <XZEquipmentCellBaseDataSource>
@end
/*
裝備圈裝備發(fā)布者協(xié)議
*/
@protocol XZEquipmentUserCellDataSource <NSObject>
@property (nonatomic,strong) NSString *headPortrait;
//用戶
@property (nonatomic,strong) NSString *name;
@property (nonatomic,strong) NSString *levelName;
@end
/*
裝備圈裝備 相關(guān)的 協(xié)議: 點(diǎn)贊數(shù) 分享數(shù) 下載數(shù)
*/
@protocol XZEquipmentRelateCellDataSource <NSObject>
//下載量
@property (nonatomic,assign) NSInteger downloadCount;
//分享量
@property (nonatomic,assign) NSInteger shareCount;
//關(guān)注狀態(tài) 1已關(guān)注 0未關(guān)注
@property (nonatomic,assign)BOOL careStatus;
@end
/*
裝備圈裝備協(xié)議 繼承多個(gè)接口 裝備的一個(gè)功能就是一個(gè)協(xié)議
*/
@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
/*
裝備視頻的協(xié)議
*/
@protocol XZEquipmentVideoCellDataSource <XZEquipmentCellDataSource>
//視頻鏈接
@property (nonatomic,strong) NSString *videoUrl;
//視頻主題
@property (nonatomic,strong) NSString *videoImageUrl;
@end
/*
裝備圖片的協(xié)議
*/
@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
獨(dú)立業(yè)務(wù)
滾動(dòng)廣告
@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{
//數(shù)據(jù)源
return self.dataArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
XZEquipment *equipment = self.dataArray[indexPath.row];
//如果裝備樣式未知 不用f計(jì)算高度
if (equipment.cellType == XZEquipmentCellTypeUnknow) {
return CGFLOAT_MIN;
}
//正確則 自動(dòng)動(dòng)態(tài)布局高度
return UITableViewAutomaticDimension;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//沒(méi)有接口按順序各個(gè)組件都呈現(xiàn)一個(gè)
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:{
// 未知 則返回一個(gè)空的高度為0 的cell
UITableViewCell *cell = [UITableViewCell cellGetTableView:self.tableView];
return cell;
}
}
}