| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- //
- // SystemmessageViewController.m
- // jitao
- //
- // Created by 罗云飞 on 2017/12/9.
- // Copyright © 2017年 罗云飞. All rights reserved.
- //
- #import "SystemmessageViewController.h"
- #import "SystemmessageCell.h"
- #import "SystemModel.h"
- #import "SystemDetailViewController.h"
- @interface SystemmessageViewController ()<UITableViewDelegate,UITableViewDataSource>{
- UITableView *newtableView;
- NSMutableArray *dataArray;
- int pageNo;
- }
- @end
- @implementation SystemmessageViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self setNavTitle:@"系统消息"];
- [self dataInitialization];
- [self SystemmessageNetworkrequest:nil];
- [self loadsView];
- [self addRefreshing];
-
- // Do any additional setup after loading the view.
- }
- #pragma mark -----系统列表网络请求------
- - (void)SystemmessageNetworkrequest:(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 = pageNo+1;
- }
-
- NSMutableDictionary *parameters = NewMutableDictionaryInit;
- [parameters safeSetObject:@(pageNumberIndex) forKey:@"pageNo"];//页码
- [parameters safeSetObject:@"10" forKey:@"pageSize"];//页面显示数
- [parameters safeSetObject:@"1" forKey:@"subject"];//消息类型 1-系统消息 ,2-推荐消息
- [NetworkRequestManager requestPostWithInterfacePrefix:JT_listMessage parameters:parameters onSuccess:^(id requestData) {
- [self dismiss:object];
- NSLog(@"服务器返回数据:%@",requestData);
- if ([requestData[@"error"] count] !=0) {
- for (NSDictionary *dic in requestData[@"error"]) {
- [MBProgressHUD showError:dic[@"message"] toView:self.view];
- }
- }else{
- pageNo = pageNumberIndex;
- if ([object isKindOfClass:[MJRefreshNormalHeader class]]) {//下拉要清空数组
- [dataArray removeAllObjects];
- }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]) {//上拉
- if ([requestData[@"data"][@"list"] count]<=0) {
- [self.view makeToast:NewConnectServerNoMoreDataTitle duration:1.0 position:CSToastPositionBottom];
- }
- }
- for (NSDictionary *dic in requestData[@"data"][@"list"]) {
- SystemModel *model = [[SystemModel 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)dataInitialization{
- dataArray = NewMutableArrayInit;
- pageNo = 1;
- }
- #pragma mark ----加载界面
- - (void)loadsView{
-
- [self.view addSubview:newtableView = [NewControlPackage tableViewInitWithFrame:CGRectMake(0, NavHeader, SCREEN_WIDTH, SCREEN_HEIGHT-NavHeader) backgroundColor:NewNavigationColor style:UITableViewStyleGrouped 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";
- SystemmessageCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell];
- if (cell == nil) {
- cell = [[SystemmessageCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell];
- }
- [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//(这种是没有点击后的阴影效果)
- cell.accessoryType = UITableViewCellAccessoryNone;
- [cell assignment:dataArray[indexPath.row]];
- if (indexPath.row == dataArray.count-1) {
- cell.line.hidden = YES;
- }
- return cell;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return fitScreenWidth(67);
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- SystemModel *model = dataArray[indexPath.row];
- SystemDetailViewController *vc = [[SystemDetailViewController alloc] init];
- vc.messageId = model.messageId;
-
- NewPushViewController(vc);
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
- return CGFLOAT_MIN;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
- return 10;
- }
- - (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 *newvc = newtableView;
- newvc.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
-
- if ([NetworkRequestManager connectedToNetwork]) {
-
- [weakSelf SystemmessageNetworkrequest:newvc.mj_header];
-
- }else{
- [newvc.mj_header endRefreshing];
- }
- }];
-
- newvc.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
-
- if ([NetworkRequestManager connectedToNetwork]) {
-
- [weakSelf SystemmessageNetworkrequest:newvc.mj_footer];
-
- }else{
- [newvc.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];
- }
- }
- - (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
|