// // ThirdViewController.m // PersonalCenter // // Created by Arch on 2017/6/16. // Copyright © 2017年 mint_bin. All rights reserved. // #import "ThirdViewController.h" #import "HomeSubItemModel.h" #import "IndexAllCell.h" #import "MoveViewController.h" #import "BookTeacherDetailVC.h" #import "BookWCDetailVC.h" #import "BookListenVC.h" #import "BookListDetailVC.h" #import "IndexMoreVC.h" static NSString *const ThirdViewControllerCollectionViewCellIdentifier = @"ThirdViewControllerCollectionViewCell"; @interface ThirdViewController () @property (nonatomic, strong) NSMutableArray *dataSource; @property(nonatomic, strong) UITableView *tableView; @end @implementation ThirdViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = UIColorHex(0xF8F9FB); [self creatTableView]; } - (NSMutableArray *)dataSource { if (!_dataSource) { _dataSource = [NSMutableArray array]; } return _dataSource; } - (void)creatTableView { _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 10, SCREEN_WIDTH, SCREEN_HEIGHT - NAVH - 150)]; _tableView.delegate = self; _tableView.dataSource = self; _tableView.showsVerticalScrollIndicator = NO; _tableView.showsHorizontalScrollIndicator = NO; _tableView.separatorStyle = UITableViewCellSeparatorStyleNone; _tableView.rowHeight = 50; [self.view addSubview:_tableView]; } - (void)setDataArray:(NSArray *)array { [self.dataSource removeAllObjects]; for (NSDictionary *dict in array) { NSMutableArray * addArray = [NSMutableArray array]; IndexAllModel * model = [IndexAllModel modelWithDictionary:dict]; for (NSDictionary * subDict in model.Items) { HomeSubItemModel * submodel = [HomeSubItemModel modelWithDictionary:subDict]; [addArray addObject:submodel]; } model.Items = addArray.mutableCopy; [self.dataSource addObject:model]; } [self.tableView reloadData]; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.dataSource.count; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return UITableViewAutomaticDimension; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { WS(weakSelf); IndexAllModel *model = self.dataSource[indexPath.row]; IndexAllCell * cell = [IndexAllCell configCell1:tableView indexPath:indexPath]; [cell setDataWithModel:model]; cell.ClickRowBlock = ^(CollectModelType type, NSInteger Id) { [weakSelf pushVC:type Id:Id]; }; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { HomeSubItemModel * model = self.dataSource[indexPath.row]; [tableView deselectRowAtIndexPath:indexPath animated:YES]; BookTeacherDetailVC * vc = [BookTeacherDetailVC initBookTeacherDetailVC]; vc.Id = model.Id; [self.navigationController pushViewController:vc animated:YES]; } - (void)pushVC:(CollectModelType)type Id:(NSInteger)Id { switch (type) { case CollectModel_StoreBook: { BookListDetailVC * vc = [BookListDetailVC initBookListDetailVC]; vc.Id = Id; [self.navigationController pushViewController:vc animated:YES]; } break; case CollectModel_StoreVideo: { BookWCDetailVC * vc = [BookWCDetailVC initBookWCDetailVC]; vc.Id = Id; [self.navigationController pushViewController:vc animated:YES]; } break; case CollectModel_StoreSound: { BookListenVC * vc = [BookListenVC initBookListenVC]; vc.Id = Id; vc.MediaType = MediaMusicType; [self.navigationController pushViewController:vc animated:YES]; } break; case CollectModel_Teacher: { BookTeacherDetailVC * vc = [BookTeacherDetailVC initBookTeacherDetailVC]; vc.Id = Id; [self.navigationController pushViewController:vc animated:YES]; } break; case CollectModel_Organization: { } break; default: { MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC]; vc.type = type; vc.Id = Id; [self.navigationController pushViewController:vc animated:YES]; } break; } } @end