Commit a315aea6 cgx

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

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