You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
276 lines
9.9 KiB
276 lines
9.9 KiB
![]()
2 years ago
|
//
|
||
|
// ProblemViewController.m
|
||
|
// LekangGuard
|
||
|
//
|
||
|
// Created by ecell on 2022/12/30.
|
||
|
//
|
||
|
|
||
|
#import "ProblemViewController.h"
|
||
|
#import "ProblemTableViewCell.h"
|
||
|
#import "ProblemCollectionViewCell.h"
|
||
|
#import "ProblemTableViewController.h"
|
||
|
#import "ProblemDetailsViewController.h"
|
||
|
#import "ProblemDetailsViewController.h"
|
||
|
|
||
|
@interface ProblemViewController ()<WSLWaterFlowLayoutDelegate,UICollectionViewDelegate,UICollectionViewDataSource>
|
||
|
@property (nonatomic ,strong) UIView *topView;
|
||
|
@property (nonatomic ,strong) UIView *headerView;
|
||
|
|
||
|
@property (nonatomic ,strong) CommonTableView *problemTable;
|
||
|
|
||
|
@property (nonatomic, assign) WSLWaterFlowLayoutStyle flowLayoutStyle;
|
||
|
@property (nonatomic ,strong) UICollectionView *menuCollectionView;
|
||
|
|
||
|
@property (nonatomic ,strong) NSMutableArray *titleArr;
|
||
|
|
||
|
|
||
|
|
||
|
@end
|
||
|
|
||
|
@implementation ProblemViewController
|
||
|
|
||
|
- (void)viewDidLoad {
|
||
|
[super viewDidLoad];
|
||
|
// Do any additional setup after loading the view.
|
||
|
self.zx_navTitle = GJText(@"常见问题");
|
||
|
[self SubTopView];
|
||
|
[self.view addSubview:self.problemTable];
|
||
|
[self GetHotMessage];
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
#pragma mark 查询热点问题
|
||
|
/// 查询热点问题
|
||
|
- (void)GetHotMessage
|
||
|
{
|
||
|
[self.modelListArr removeAllObjects];
|
||
|
[UICommon MessageUpload:@"加载中"];
|
||
|
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
|
||
|
[[[APIManager sharedManager] APGET:HotMessage_URL parameters:parameters resultClass:nil] subscribeNext:^(NSArray *arr) {
|
||
|
self.problemTable.frame = CGRectMake(20, self.topView.bottom, SCREEN_WIDTH-40, arr.count*Adapted(48));
|
||
|
for (NSDictionary *dic in arr)
|
||
|
{
|
||
|
ProblemModel *model = [ProblemModel yy_modelWithJSON:dic];
|
||
|
[self.modelListArr addObject:model];
|
||
|
}
|
||
|
self.problemTable.cellRow = arr.count;
|
||
|
[self.problemTable reloadData];
|
||
|
// [self GetMessageCategory];
|
||
|
} error:^(NSError * _Nullable error) {
|
||
|
NSDictionary *dic = error.userInfo;
|
||
|
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]];
|
||
|
}];
|
||
|
}
|
||
|
|
||
|
#pragma mark 查询问题分类
|
||
|
/// 查询问题分类
|
||
|
- (void)GetMessageCategory
|
||
|
{
|
||
|
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
|
||
|
[[[APIManager sharedManager] APGET:MessageCategory_URL parameters:parameters resultClass:nil] subscribeNext:^(NSArray *arr) {
|
||
|
self.titleArr = [NSMutableArray new];
|
||
|
for (NSDictionary *dic in arr)
|
||
|
{
|
||
|
ProblemModel *model = [ProblemModel yy_modelWithJSON:dic];
|
||
|
[self.titleArr addObject:model];
|
||
|
}
|
||
|
[self SubHeaderView];
|
||
|
[self subCollectionView];
|
||
|
[self.menuCollectionView reloadData];
|
||
|
[UICommon HidenLoading];
|
||
|
} error:^(NSError * _Nullable error) {
|
||
|
NSDictionary *dic = error.userInfo;
|
||
|
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]];
|
||
|
}];
|
||
|
}
|
||
|
|
||
|
- (void)subCollectionView
|
||
|
{
|
||
|
WSLWaterFlowLayout *FlowLayout = [[WSLWaterFlowLayout alloc] init];
|
||
|
FlowLayout.delegate = self;
|
||
|
FlowLayout.flowLayoutStyle = self.flowLayoutStyle;
|
||
|
|
||
|
_menuCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(20, self.headerView.bottom+10, SCREEN_WIDTH-40, SCREEN_HEIGHT-self.headerView.bottom-20) collectionViewLayout:FlowLayout];
|
||
|
_menuCollectionView.backgroundColor = KKClearColor;
|
||
|
_menuCollectionView.dataSource = self;
|
||
|
_menuCollectionView.delegate = self;
|
||
|
_menuCollectionView.showsVerticalScrollIndicator = NO;
|
||
|
_menuCollectionView.alwaysBounceVertical = NO;
|
||
|
_menuCollectionView.scrollEnabled = NO;
|
||
|
if (@available(iOS 11.0, *))
|
||
|
_menuCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
|
||
|
[_menuCollectionView registerClass:ProblemCollectionViewCell.class forCellWithReuseIdentifier:NSStringFromClass(ProblemCollectionViewCell.class)];
|
||
|
[self.view addSubview:_menuCollectionView];
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
#pragma mark - WSLWaterFlowLayoutDelegate
|
||
|
//返回每个item大小
|
||
|
- (CGSize)waterFlowLayout:(WSLWaterFlowLayout *)waterFlowLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
|
||
|
{
|
||
|
return CGSizeMake((SCREEN_WIDTH-45)/3, Adapted(50));
|
||
|
}
|
||
|
|
||
|
/** 头视图Size */
|
||
|
-(CGSize )waterFlowLayout:(WSLWaterFlowLayout *)waterFlowLayout sizeForHeaderViewInSection:(NSInteger)section
|
||
|
{
|
||
|
return CGSizeMake(SCREEN_WIDTH, 0);
|
||
|
}
|
||
|
/** 列数*/
|
||
|
-(CGFloat)columnCountInWaterFlowLayout:(WSLWaterFlowLayout *)waterFlowLayout
|
||
|
{
|
||
|
return 3;
|
||
|
}
|
||
|
|
||
|
/** 列间距*/
|
||
|
-(CGFloat)columnMarginInWaterFlowLayout:(WSLWaterFlowLayout *)waterFlowLayout
|
||
|
{
|
||
|
return 3;
|
||
|
}
|
||
|
/** 行间距*/
|
||
|
-(CGFloat)rowMarginInWaterFlowLayout:(WSLWaterFlowLayout *)waterFlowLayout
|
||
|
{
|
||
|
return 3;
|
||
|
}
|
||
|
/** 边缘之间的间距*/
|
||
|
-(UIEdgeInsets)edgeInsetInWaterFlowLayout:(WSLWaterFlowLayout *)waterFlowLayout
|
||
|
{
|
||
|
return UIEdgeInsetsMake(5, 0, 5, 0);
|
||
|
}
|
||
|
|
||
|
#pragma mark - UICollectionView数据源
|
||
|
//组个数
|
||
|
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
|
||
|
{
|
||
|
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
//组内成员个数
|
||
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
|
||
|
{
|
||
|
return self.titleArr.count;
|
||
|
}
|
||
|
|
||
|
|
||
|
//设置元素内容
|
||
|
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
|
||
|
{
|
||
|
ProblemCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass(ProblemCollectionViewCell.class) forIndexPath:indexPath];
|
||
|
ProblemModel *model = self.titleArr[indexPath.row];
|
||
|
cell.titleText = model.categoryName;
|
||
|
|
||
|
return cell;
|
||
|
}
|
||
|
|
||
|
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
|
||
|
{
|
||
|
ProblemModel *model = self.titleArr[indexPath.row];
|
||
|
ProblemTableViewController *vc = [ProblemTableViewController new];
|
||
|
vc.titleStr = model.categoryName;
|
||
|
vc.pModel = model;
|
||
|
[self.navigationController pushViewController:vc animated:YES];
|
||
|
}
|
||
|
|
||
|
|
||
|
- (CommonTableView *)problemTable
|
||
|
{
|
||
|
if (!_problemTable)
|
||
|
{
|
||
|
kWeakSelf(self)
|
||
|
_problemTable = [[CommonTableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain cellHeight:48 cellRow:0 isAdaptive:NO isLine:YES commonCell:ProblemTableViewCell.class createCell:^(ZZTableViewCell * _Nonnull cells, NSIndexPath * _Nonnull indexPath) {
|
||
|
ProblemTableViewCell *cell = (ProblemTableViewCell *)cells;
|
||
|
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
|
||
|
if (indexPath.row < weakself.modelListArr.count)
|
||
|
{
|
||
|
ProblemModel *model = weakself.modelListArr[indexPath.row];
|
||
|
cell.cenText = model.content;
|
||
|
}
|
||
|
|
||
|
} selectedCell:^(UITableView * _Nonnull tableView, NSIndexPath * _Nonnull indexPath) {
|
||
|
ProblemModel *model = weakself.modelListArr[indexPath.row];
|
||
|
ProblemDetailsViewController *vc = [ProblemDetailsViewController new];
|
||
|
vc.pModel = model;
|
||
|
[weakself.navigationController pushViewController:vc animated:YES];
|
||
|
|
||
|
} DidscrollView:^(UIScrollView * _Nonnull scrollView) {
|
||
|
|
||
|
}];
|
||
|
_problemTable.backgroundColor = KKWhiteColorColor;
|
||
|
[UICommon setExtraCellLineHidden:_problemTable];
|
||
|
}
|
||
|
return _problemTable;
|
||
|
}
|
||
|
|
||
|
- (void)SubTopView
|
||
|
{
|
||
|
self.topView = [UIView new];
|
||
|
self.topView.frame = CGRectMake(20, iPhoneX_NavHeight+20, SCREEN_WIDTH-40, Adapted(46));
|
||
|
self.topView.backgroundColor = KKWhiteColorColor;
|
||
|
[self.view addSubview:self.topView];
|
||
|
|
||
|
|
||
|
UIImageView *leftImg = [UICommon ui_imageView:CGRectZero fileName:@"icon_hot_issue"];
|
||
|
[self.view addSubview:leftImg];
|
||
|
[leftImg mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.equalTo(self.view).offset(15);
|
||
|
make.top.equalTo(self.topView).offset(10);
|
||
|
make.size.mas_equalTo(CGSizeMake(Adapted(leftImg.image.size.width), Adapted(leftImg.image.size.height)));
|
||
|
}];
|
||
|
|
||
|
UILabel *titleLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:FontADA_(12) textColor:KKWhiteColorColor text:GJText(@"常见问题") Radius:0];
|
||
|
[self.view addSubview:titleLabel];
|
||
|
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.equalTo(self.topView).offset(10);
|
||
|
make.centerY.equalTo(leftImg);
|
||
|
}];
|
||
|
|
||
|
UIButton *moreBtn = [UICommon ui_buttonSimple:CGRectZero font:FontADA_(13) normalColor:KKGrey143 normalText:GJText(@"更多") click:^(id x) {
|
||
|
|
||
|
ProblemTableViewController *vc = [ProblemTableViewController new];
|
||
|
vc.titleStr = GJText(@"热门问题");
|
||
|
[self.navigationController pushViewController:vc animated:YES];
|
||
|
vc.modelArr = self.modelListArr;
|
||
|
}];
|
||
|
[self.topView addSubview:moreBtn];
|
||
|
[moreBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.right.equalTo(self.topView.mas_right);
|
||
|
make.centerY.equalTo(leftImg);
|
||
|
make.size.mas_equalTo(CGSizeMake(60, Adapted(leftImg.image.size.height)));
|
||
|
}];
|
||
|
}
|
||
|
|
||
|
- (void)SubHeaderView
|
||
|
{
|
||
|
_headerView = [UIView new];
|
||
|
_headerView.backgroundColor = KKClearColor;
|
||
|
_headerView.frame = CGRectMake(20, self.problemTable.bottom+20, SCREEN_WIDTH-40, 20);
|
||
|
[self.view addSubview:_headerView];
|
||
|
|
||
|
UIImageView *line = [UIImageView new];
|
||
|
line.frame = CGRectMake(0, 2.5, 3, 15);
|
||
|
line.backgroundColor = KKMainColor;
|
||
|
[_headerView addSubview:line];
|
||
|
|
||
|
UILabel *titleLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:FontADA_(13) textColor:KKTextBlackColor text:GJText(@"问题分类") Radius:0];
|
||
|
[_headerView addSubview:titleLabel];
|
||
|
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.equalTo(line).offset(10);
|
||
|
make.centerY.equalTo(line);
|
||
|
}];
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
#pragma mark - Navigation
|
||
|
|
||
|
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
||
|
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
||
|
// Get the new view controller using [segue destinationViewController].
|
||
|
// Pass the selected object to the new view controller.
|
||
|
}
|
||
|
*/
|
||
|
|
||
|
@end
|