152 lines
4.7 KiB
Mathematica
152 lines
4.7 KiB
Mathematica
|
|
//
|
||
|
|
// CHXQMusicListVC.m
|
||
|
|
// romantic
|
||
|
|
//
|
||
|
|
// Created by bj_szd on 2022/4/8.
|
||
|
|
// Copyright © 2022 romantic. All rights reserved.
|
||
|
|
//
|
||
|
|
|
||
|
|
#import "CHXQMusicListVC.h"
|
||
|
|
#import "CHXQMusicListCell.h"
|
||
|
|
|
||
|
|
@interface CHXQMusicListVC ()<UITableViewDelegate, UITableViewDataSource>
|
||
|
|
|
||
|
|
@property (nonatomic,strong) UITableView *tableView;
|
||
|
|
@property (nonatomic,strong) NSMutableArray *dataArray;
|
||
|
|
@property (nonatomic,assign) NSInteger page;
|
||
|
|
|
||
|
|
@end
|
||
|
|
|
||
|
|
@implementation CHXQMusicListVC
|
||
|
|
|
||
|
|
#pragma mark - life cycle
|
||
|
|
- (void)viewDidLoad {
|
||
|
|
[super viewDidLoad];
|
||
|
|
|
||
|
|
[self loadBar:YES needBack:YES needBackground:NO];
|
||
|
|
self.titleLabel.text = @"我的音乐";
|
||
|
|
// self.leftButtonView.image = ImageNamed(@"my_back");
|
||
|
|
// self.titleLabel.textColor = HEXCOLOR(0x333333);
|
||
|
|
|
||
|
|
[self createUI];
|
||
|
|
|
||
|
|
// 设置刷新
|
||
|
|
[self setupRefresh];
|
||
|
|
// 请求
|
||
|
|
[self loadDataIsRefresh:YES];
|
||
|
|
}
|
||
|
|
|
||
|
|
-(void)createUI {
|
||
|
|
self.view.backgroundColor = kWhiteColor;
|
||
|
|
|
||
|
|
[self.view addSubview:self.tableView];
|
||
|
|
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
|
make.top.equalTo(self.view).offset(TOP_BAR_HEIGHT);
|
||
|
|
make.left.right.bottom.equalTo(self.view);
|
||
|
|
}];
|
||
|
|
}
|
||
|
|
|
||
|
|
#pragma mark - network request
|
||
|
|
/** 设置刷新 */
|
||
|
|
- (void)setupRefresh {
|
||
|
|
[ZJUIUtil refreshWithHeader:self.tableView refresh:^{
|
||
|
|
WEAK_SELF
|
||
|
|
weakSelf.page = 1;
|
||
|
|
[weakSelf loadDataIsRefresh:YES];
|
||
|
|
}];
|
||
|
|
[ZJUIUtil refreshWithFooter:self.tableView refresh:^{
|
||
|
|
WEAK_SELF
|
||
|
|
weakSelf.page ++;
|
||
|
|
[weakSelf loadDataIsRefresh:NO];
|
||
|
|
}];
|
||
|
|
// 解决加载更多数据时界面跳动问题
|
||
|
|
self.tableView.estimatedRowHeight = 0;
|
||
|
|
self.tableView.estimatedSectionHeaderHeight = 0;
|
||
|
|
self.tableView.estimatedSectionFooterHeight = 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
/** 加载数据 */
|
||
|
|
- (void)loadDataIsRefresh:(BOOL)isRefresh {
|
||
|
|
if (isRefresh) {
|
||
|
|
self.page = 1;
|
||
|
|
[self.dataArray removeAllObjects];
|
||
|
|
[self.tableView reloadData];
|
||
|
|
}
|
||
|
|
|
||
|
|
NSDictionary *dict = @{@"page":@(self.page), @"page_limit":@"1000"};
|
||
|
|
[RCMicHTTP postWithURLString:@"api/music/get_user_music_list" parameters:dict response:^(RCMicHTTPResult *result) {
|
||
|
|
if (result.success) {
|
||
|
|
if (result.errorCode == 200 && [result.content isKindOfClass:NSArray.class]) {
|
||
|
|
NSArray *arr = [RoomMusicModel mj_objectArrayWithKeyValuesArray:result.content];
|
||
|
|
[self.dataArray addObjectsFromArray:arr];
|
||
|
|
[self.tableView reloadData];
|
||
|
|
}else {
|
||
|
|
[SVProgressHUD showInfoWithStatus:result.message];
|
||
|
|
}
|
||
|
|
}else {
|
||
|
|
[SVProgressHUD showInfoWithStatus:@"网络错误"];
|
||
|
|
}
|
||
|
|
|
||
|
|
[self.tableView.mj_header endRefreshing];
|
||
|
|
[self.tableView.mj_footer endRefreshing];
|
||
|
|
}];
|
||
|
|
}
|
||
|
|
|
||
|
|
#pragma mark - UITableViewDelegate && UITableViewDataSource
|
||
|
|
|
||
|
|
- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
||
|
|
return self.dataArray.count;
|
||
|
|
}
|
||
|
|
|
||
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||
|
|
CHXQMusicListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CHXQMusicListCell"];
|
||
|
|
cell.selectionStyle = NO;
|
||
|
|
RoomMusicModel *model = self.dataArray[indexPath.row];
|
||
|
|
cell.nameLab.text = model.music_name;
|
||
|
|
cell.singerLab.text = model.singer;
|
||
|
|
|
||
|
|
// WEAK_SELF
|
||
|
|
// [cell.playBtn buttonAddTaget:^(UIButton *btn) {
|
||
|
|
// if (weakSelf.onPlayBlock) {
|
||
|
|
// weakSelf.onPlayBlock([weakSelf.dataArray copy], indexPath.row);
|
||
|
|
// }
|
||
|
|
// [weakSelf.navigationController popViewControllerAnimated:YES];
|
||
|
|
// } forControlEvents:UIControlEventTouchUpInside];
|
||
|
|
|
||
|
|
return cell;
|
||
|
|
}
|
||
|
|
|
||
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
||
|
|
// RoomMusicModel *model = self.dataArray[indexPath.row];
|
||
|
|
// if (self.onChooseBlock) {
|
||
|
|
// self.onChooseBlock(model);
|
||
|
|
// }
|
||
|
|
if (self.onPlayBlock) {
|
||
|
|
self.onPlayBlock([self.dataArray copy], indexPath.row);
|
||
|
|
}
|
||
|
|
[self.navigationController popViewControllerAnimated:YES];
|
||
|
|
}
|
||
|
|
|
||
|
|
#pragma mark - getter
|
||
|
|
- (UITableView *)tableView {
|
||
|
|
if (!_tableView) {
|
||
|
|
_tableView = [[UITableView alloc] initWithFrame:CGRectZero];
|
||
|
|
_tableView.delegate = self;
|
||
|
|
_tableView.dataSource = self;
|
||
|
|
[_tableView registerNib:[UINib nibWithNibName:@"CHXQMusicListCell" bundle:nil] forCellReuseIdentifier:@"CHXQMusicListCell"];
|
||
|
|
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
||
|
|
_tableView.backgroundColor = kClearColor;
|
||
|
|
_tableView.rowHeight = 65;
|
||
|
|
}
|
||
|
|
return _tableView;
|
||
|
|
}
|
||
|
|
|
||
|
|
- (NSMutableArray *)dataArray {
|
||
|
|
if (!_dataArray) {
|
||
|
|
_dataArray = [NSMutableArray array];
|
||
|
|
}
|
||
|
|
return _dataArray;
|
||
|
|
}
|
||
|
|
|
||
|
|
@end
|