| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310 |
- //
- // ZCBKViewController.m
- // jitao
- //
- // Created by 罗云飞 on 2018/8/19.
- // Copyright © 2018年 罗云飞. All rights reserved.
- //
- #import "ZCBKViewController.h"
- #import "ZCBKCell.h"
- #import "ZCJDModel.h"
- #import "TongyongDetailViewController.h"
- #import "FaDetaiH5ViewController.h"
- #import "FaXianDetailViewController.h"
- @interface ZCBKViewController ()<UITableViewDelegate,UITableViewDataSource>{
- UITableView *newtableView;
- NSMutableArray *dataArray;
- int pageIndex;
- int pageSize;
- int pageNumber;
- UIView *showView;
- }
- @end
- @implementation ZCBKViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self setNavTitle:@"知产百科"];
- [self dataInitialization];
- [self loadsView];
- [self addRefreshing];
- [self networkRequest:nil];
- // Do any additional setup after loading the view.
- }
- - (void)dataInitialization{
- dataArray = NewMutableArrayInit;
- pageIndex = 1;
- pageSize = 10;
- pageNumber = 1;
- }
- - (void)networkRequest:(id)object
- {
- int pageNumberIndex=1;
-
- if (!object) {
- [MBProgressHUD showLoadToView:self.view title:@"请稍后..."];
- }else if ([object isKindOfClass:[MJRefreshNormalHeader class]]) {
- pageNumberIndex = 1;
- }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]) {
- pageNumberIndex = pageNumber+1;
- }
-
- NSMutableDictionary *parameters = NewMutableDictionaryInit;
- [parameters safeSetObject:@(pageSize) forKey:@"pageSize"];
- [parameters safeSetObject:@(pageNumberIndex) forKey:@"pageNo"];
-
- [NetworkRequestManager requestGetWithInterfacePrefix:JT_NewlistEncyclopedia parameters:parameters onSuccess:^(id requestData) {
- [self dismiss:object];
- if ([requestData[@"error"] count] !=0) {
- for (NSDictionary *dic in requestData[@"error"]) {
- [MBProgressHUD showError:dic[@"message"] toView:self.view];
- }
- }else{
- pageNumber = pageNumberIndex;
- if ([object isKindOfClass:[MJRefreshNormalHeader class]] || pageNumber==1) {
- [dataArray removeAllObjects];
- }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]) {
- NSMutableArray *arr = requestData[@"data"][@"list"];
- if ([arr count]<=0) {
- [[[UIApplication sharedApplication].delegate window] makeToast:NewConnectServerNoMoreDataTitle duration:1.0 position:CSToastPositionBottom];
- return;
- }
- }
- for (NSDictionary *dic in requestData[@"data"][@"list"]) {
- ZCJDModel *model = [[ZCJDModel alloc] initWithDictionary:dic error:nil];
- [dataArray addObject:model];
- }
- //查询不到类型底图
- if (dataArray.count<=0) {
- [self addErrorLoadingFrame:CGRectMake(0, NavHeader, newtableView.width, newtableView.height) title:@"暂无订单" buttonTitle:nil imageString:NewNoDataErrorImage];
- }else {
- [self hideReloadingview];
- [newtableView reloadData];
- }
- }
- } onFailure:^{
- [self dismiss:object];
- }];
- }
- #pragma mark ----加载界面
- - (void)loadsView{
- [self.view addSubview:newtableView = [NewControlPackage tableViewInitWithFrame:CGRectMake(0, NavHeader, SCREEN_WIDTH, SCREEN_HEIGHT-NavHeader) backgroundColor:NewGroupTableViewBackgroundColor style:1 delegate:self dataSource:self showsHorizontalScrollIndicator:NO showsVerticalScrollIndicator:NO hidden:NO tag:100 userInteractionEnabled:YES]];
- newtableView.separatorStyle = NO;
- }
- #pragma mark-------------------------UITableView------------------------------------
- -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return 1;
- }
- //返回每段行数
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return dataArray.count;
- }
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *Cell = @"Cell";
- ZCBKCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell];
- if (cell == nil) {
- cell = [[ZCBKCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell];
- }
- [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//(这种是没有点击后的阴影效果)
- cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
- if (dataArray.count>0) {
- ZCJDModel *model = dataArray[indexPath.row];
- cell.title.text = model.title;
- }
- return cell;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return 45;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- if (dataArray.count>0) {
- ZCJDModel *model = dataArray[indexPath.row];
- // TongyongDetailViewController *vc = [[TongyongDetailViewController alloc] init];
- // vc.title = model.title;
- // vc.neirong = model.content;
- // vc.time = model.releaseDate;
- // vc.type = @"百科";
- // NewPushViewController(vc);
- // FaDetaiH5ViewController *vc = [[FaDetaiH5ViewController alloc] init];
- // vc.type = @"资讯";
- // vc.ID = model.ID;
- // NewPushViewController(vc);
-
- FaXianDetailViewController *vc = [FaXianDetailViewController new];
- vc.title = model.title;
- vc.neirong = model.content;
- vc.time = model.releaseDate;
- vc.type = @"百科";
- vc.titleimg = model.titleImg;
- NewPushViewController(vc);
- }
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
- return CGFLOAT_MIN;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
- return CGFLOAT_MIN;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
- return [[UIView alloc] init];
- }
- - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
- return [[UIView alloc] init];
- }
- #pragma mark - 上拉下拉初始化
- - (void)addRefreshing
- {
-
- __weak typeof(self) weakSelf = self;
- __weak UITableView *tableView = newtableView;
- tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
-
- if ([NetworkRequestManager connectedToNetwork]) {
- [weakSelf networkRequest:tableView.mj_header];
-
- }else{
- [tableView.mj_header endRefreshing];
- }
- }];
-
- tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
-
- if ([NetworkRequestManager connectedToNetwork]) {
-
- [weakSelf networkRequest:tableView.mj_footer];
-
- }else{
- [tableView.mj_footer endRefreshing];
- }
- }];
- }
- - (void)dismiss:(id)object
- {
- if ([object isKindOfClass:[MJRefreshNormalHeader class]]) {
-
- __weak UITableView *newvc = newtableView;
- [newvc.mj_header endRefreshing];
-
- }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]){
-
- __weak UITableView *newvc = newtableView;
- [newvc.mj_footer endRefreshing];
-
- }else {
- [MBProgressHUD hideHUDForView:self.view];
- }
- }
- #pragma mark- 外部触发自动刷新
- - (void)autoDownRefresh
- {
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [self autoRefresh];
- });
- }
- #pragma mark- 网络请求
- - (void)autoRefresh
- {
- __weak UITableView *tableView = newtableView;
- [tableView.mj_header beginRefreshing];
- }
- #pragma mark 初始化展示框
- - (void) addErrorLoadingFrame:(CGRect)frame title:(NSString *)text buttonTitle:(NSString *)buttonText imageString:(NSString *)image
- {
- if(!showView)
- {
- [self.view addSubview:showView = [[UIView alloc] initWithFrame:frame]];
- [showView setHidden:NO];
- [showView setBackgroundColor:NewBgGrayColor];
-
- UIImage *NOimg = [UIImage imageNamed:image];
- UIImageView *tempIcon = [[UIImageView alloc]initWithImage:NOimg];
- [showView addSubview:tempIcon];
- tempIcon.sd_layout
- .leftSpaceToView(showView, (showView.width/2)-(NOimg.size.width/4.0f))
- .topSpaceToView(showView, (showView.height/2)-100.0f-(NOimg.size.height/4.0f))
- .widthIs(NOimg.size.width/2.0f)
- .heightIs(NOimg.size.height/2.0f);
-
- UILabel *tipLab = [UILabel new];
- [showView addSubview:tipLab];
- [tipLab setText:text];
- [tipLab setTextAlignment:NSTextAlignmentCenter];
- [tipLab setTextColor:NewLightGrayColor];
- [tipLab setBackgroundColor:NewClearColor];
- [tipLab setFont:NewAutoFont(16.0)];
- tipLab.sd_layout
- .leftEqualToView(showView)
- .rightEqualToView(showView)
- .topSpaceToView(tempIcon,10)
- .heightIs(20.0);
-
- if (buttonText.length>0) {
- UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
- [showView addSubview:button];
- [button setTitle:buttonText forState:UIControlStateNormal];
- [button setTitleColor:NewNavigationColor forState:UIControlStateNormal];
- ViewBorderRadius(button, 16, 2, NewNavigationColor);
- [button addTarget:self action:@selector(reloadingData) forControlEvents:UIControlEventTouchUpInside];
- CGFloat width = [NewUtils heightforString:[NSString stringWithFormat:@"%@",buttonText] andHeight:34 fontSize:16];
-
- button.sd_layout
- .leftSpaceToView(showView, (showView.width/2)-((width+35)/2))
- .topSpaceToView(tipLab, 30.0)
- .widthIs(width+35)
- .heightIs(34);
- }
- }
-
- [UIView beginAnimations:@"ShowArrow" context:nil];
-
- [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
-
- [UIView setAnimationDuration:0.25f];
-
- [UIView setAnimationDelegate:self];
- [showView setAlpha:1.0f];
- [UIView commitAnimations];
-
- }
- - (void)hideReloadingview
- {
- [UIView animateWithDuration:0.25 animations:^{
-
- showView.hidden = YES;
-
- } completion:^(BOOL finished) {
- for (id obj in showView.subviews) {
-
- [obj removeFromSuperview];
- }
- showView = nil;
- [showView removeFromSuperview];
- }];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- /*
- #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
|