Commit a315aea6 cgx

优化首页助眠音乐出现无法显示bug

1 个父辈 45d5d79e
...@@ -10,7 +10,12 @@ ...@@ -10,7 +10,12 @@
#import "GoodSleepSoundCell.h" #import "GoodSleepSoundCell.h"
@interface DSHomeView () <UITableViewDelegate, UITableViewDataSource> @interface DSHomeView () <UITableViewDelegate, UITableViewDataSource>
/// 通用数据
@property (nonatomic, strong) NSArray *courseMusicArr; @property (nonatomic, strong) NSArray *courseMusicArr;
/// 舒眠课程数据
@property (nonatomic, strong) NSArray *courseListArr;
/// 助眠音乐数据
@property (nonatomic, strong) NSArray *helpListArr;
/// 类型数据 /// 类型数据
@property (nonatomic, strong) NSArray *typeArr; @property (nonatomic, strong) NSArray *typeArr;
@end @end
...@@ -25,8 +30,6 @@ ...@@ -25,8 +30,6 @@
self.showsVerticalScrollIndicator = NO; self.showsVerticalScrollIndicator = NO;
self.delegate = self; self.delegate = self;
self.dataSource = self; self.dataSource = self;
[self registerClass:[CourseMusicCell class] forCellReuseIdentifier:NSStringFromClass([CourseMusicCell class])];
[self registerClass:[GoodSleepSoundCell class] forCellReuseIdentifier:NSStringFromClass([GoodSleepSoundCell class])];
self.tableHeaderView = self.headerView; self.tableHeaderView = self.headerView;
} }
return self; return self;
...@@ -37,40 +40,43 @@ ...@@ -37,40 +40,43 @@
} }
- (void)updateCourseMusicCell:(CellType)type data:(NSArray *)dataArr { - (void)updateCourseMusicCell:(CellType)type data:(NSArray *)dataArr {
NSInteger index = type == CellTypeCourse ? 0 : 1; if (dataArr && dataArr.count > 0) {
CourseMusicCell *cell = (CourseMusicCell *)[self cellForRowAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0]]; if (type == CellTypeCourse) {
[cell updateCourseMusicListWithData:dataArr cellIndex:index]; self.courseListArr = dataArr;
} else if (type == CellTypeMusic) {
self.helpListArr = dataArr;
}
[self reloadData];
}
} }
- (void)updateNoiseAllTypeData:(NSArray *)typeDataArr { - (void)updateNoiseAllTypeData:(NSArray *)typeDataArr {
if (typeDataArr && typeDataArr.count > 0) { if (typeDataArr && typeDataArr.count > 0) {
self.typeArr = typeDataArr; self.typeArr = typeDataArr;
} [self reloadData];
GoodSleepSoundCell *cell = (GoodSleepSoundCell *)[self cellForRowAtIndexPath:[NSIndexPath indexPathForRow:2 inSection:0]];
if (cell) {
[cell updateNoiseAllTypeData:typeDataArr];
}
}
- (NSString *)cellIdentiferAtIndexPath:(NSIndexPath *)indexPath {
SafeSleepModel *item = self.courseMusicArr[indexPath.row];
if (item.type == CellTypeGood) {
return NSStringFromClass([GoodSleepSoundCell class]);
} else {
return NSStringFromClass([CourseMusicCell class]);
} }
} }
#pragma mark - UITableViewDelegate && UITableViewDataSource #pragma mark - UITableViewDelegate && UITableViewDataSource
- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath { - (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
HomeBasicCell *cell = [tableView dequeueReusableCellWithIdentifier:[self cellIdentiferAtIndexPath:indexPath] forIndexPath:indexPath]; NSString *cellID = [NSString stringWithFormat:@"cmg_%zd", indexPath.row];
[cell configBasicData:self.courseMusicArr[indexPath.row] cellIndex:indexPath.row];
if (indexPath.row == 2) { if (indexPath.row == 2) {
GoodSleepSoundCell *goodCell = (GoodSleepSoundCell *)cell; GoodSleepSoundCell *goodCell = [tableView dequeueReusableCellWithIdentifier:cellID];
if (!goodCell) {
goodCell = [[GoodSleepSoundCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
}
[goodCell configBasicData:self.courseMusicArr[indexPath.row] cellIndex:indexPath.row];
[goodCell updateNoiseAllTypeData:self.typeArr]; [goodCell updateNoiseAllTypeData:self.typeArr];
return goodCell;
} else {
CourseMusicCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if (!cell) {
cell = [[CourseMusicCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
}
[cell configBasicData:self.courseMusicArr[indexPath.row] cellIndex:indexPath.row];
[cell updateCourseMusicListWithData:(indexPath.row == 0 ? self.courseListArr : self.helpListArr) cellIndex:indexPath.row];
return cell;
} }
return cell;
} }
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
...@@ -105,6 +111,15 @@ ...@@ -105,6 +111,15 @@
return [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 0.001)]; return [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 0.001)];
} }
- (NSString *)cellIdentiferAtIndexPath:(NSIndexPath *)indexPath {
SafeSleepModel *item = self.courseMusicArr[indexPath.row];
if (item.type == CellTypeGood) {
return NSStringFromClass([GoodSleepSoundCell class]);
} else {
return NSStringFromClass([CourseMusicCell class]);
}
}
#pragma mark - lazy #pragma mark - lazy
- (HomeHeaderView *)headerView { - (HomeHeaderView *)headerView {
if (!_headerView) { if (!_headerView) {
...@@ -126,6 +141,20 @@ ...@@ -126,6 +141,20 @@
return _courseMusicArr; return _courseMusicArr;
} }
- (NSArray *)courseListArr {
if (!_courseListArr) {
_courseListArr = [NSArray array];
}
return _courseListArr;
}
- (NSArray *)helpListArr {
if (!_helpListArr) {
_helpListArr = [NSArray array];
}
return _helpListArr;
}
- (NSArray *)typeArr { - (NSArray *)typeArr {
if (!_typeArr) { if (!_typeArr) {
_typeArr = [NSArray array]; _typeArr = [NSArray array];
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!