123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- //
- // XYMountListViewController.m
- // Starbuds
- //
- // Created by 翟玉磊 on 2020/1/13.
- // Copyright © 2020 翟玉磊. All rights reserved.
- //
- #import "XYMountListViewController.h"
- #import "XYMountListViewModel.h"
- #import "XYMountListTableViewCell.h"
- #import "XYMountListCellModel.h"
- @interface XYMountListViewController ()<XYMountListTableViewCellDelegate>
- @property (nonatomic, readwrite, strong) XYMountListViewModel *viewModel;
- @end
- @implementation XYMountListViewController
- -(void)dealloc {
- [[NSNotificationCenter defaultCenter] removeObserver:self name:@"Refresh_Mount_listNotification" object:nil];
- }
- /// 重写init方法,配置你想要的属性
- - (instancetype)init
- {
- self = [super init];
- if (self) {
- self.prefersNavigationBarBottomLineHidden = YES;
- }
- return self;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- /// 设置
- [self _setup];
-
- /// 设置导航栏
- [self _setupNavigationItem];
-
- /// 设置子控件
- [self _setupSubViews];
-
- /// 布局子空间
- [self _makeSubViewsConstraints];
-
- [self tableViewDidTriggerHeaderRefresh];
-
- // 使用坐骑卡后刷新坐骑列表
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tableViewDidTriggerHeaderRefresh) name:@"Refresh_Mount_listNotification" object:nil];
- }
- #pragma mark — Override
- - (void)bindViewModel {
- self.viewModel = [XYMountListViewModel new];
- }
- - (UIEdgeInsets)contentInset {
- return UIEdgeInsetsMake(0, 0, NAVGATION_HEIGHT + 44.0f, 0);
- }
- - (void)tableViewDidTriggerHeaderRefresh {
- self.viewModel.pullDown = YES;
- [self.viewModel loadData:^(id responseModel) {
- [self tableViewDidFinishTriggerHeader:YES reload:YES];
- [self.tableView zyl_configEmptyViewWithType:ZYLEmptyDataViewTypeDefault emptyInfo:kLocalizedString(@"背包空空~心脏痛痛~") errorInfo:@"" offsetTop:200.0f hasData:self.viewModel.dataSource.count>0 hasError:NO reloadBlock:nil];
- } failure:^(NSError *error) {
- [self tableViewDidFinishTriggerHeader:YES reload:YES];
- [self.tableView zyl_configEmptyViewWithType:ZYLEmptyDataViewTypeDefault emptyInfo:kLocalizedString(@"背包空空~心脏痛痛~") errorInfo:error.domain offsetTop:200.0f hasData:self.viewModel.dataSource.count>0 hasError:error!=nil reloadBlock:nil];
- }];
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath {
- return [XYMountListTableViewCell cellWithTableView:tableView];
- }
- - (void)configureCell:(XYMountListTableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object {
- [cell configureModel:object];
- [cell setIndexPath:indexPath rowsInSection:self.viewModel.dataSource.count-1];
- cell.delegate = self;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- return 90.0f;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
- }
- #pragma mark — XYMountListTableViewCellDelegate
- - (void)selectUseMountAtIndexPath:(NSIndexPath *)indexPath {
- [self.viewModel selectedMountWithIndex:indexPath.row success:^(id _Nullable responseModel) {
- [self tableViewDidFinishTriggerHeader:YES reload:YES];
- } failure:^(ZYLNetworkError * _Nullable error) {
- [SVProgressHUD showInfoWithStatus:error.domain];
- }];
- }
- #pragma mark - 事件处理Or辅助方法
- #pragma mark - 初始化
- - (void)_setup{
- self.tableView.backgroundColor = Color_White;
- }
- #pragma mark - 设置导航栏
- - (void)_setupNavigationItem{
-
- }
- #pragma mark - 设置子控件
- - (void)_setupSubViews{
-
- }
- #pragma mark - 布局子控件
- - (void)_makeSubViewsConstraints{
-
- }
- #pragma mark - Setter & Getter
- @end
|