// // DetailOnlyTextViewController.m // model // // Created by MUMEI on 2018/8/6. // Copyright © 2018年 Mine. All rights reserved. // #import "DetailOnlyTextViewController.h" #import "ImageViewController.h" #import "DetailOnlyTextCell.h" #import "DetailOneImageCell.h" #import "DetailFourImageCell.h" #import "PingLunCell.h" @interface DetailOnlyTextViewController () @property (weak, nonatomic) IBOutlet UITableView *tableView; @property (strong, nonatomic) NSMutableArray *pingLunArray; @end @implementation DetailOnlyTextViewController { int i; } - (NSMutableArray *)pingLunArray { if (!_pingLunArray) { _pingLunArray = [NSMutableArray arrayWithCapacity:0]; } return _pingLunArray; } - (void)viewDidLoad { [super viewDidLoad]; self.tableView.estimatedRowHeight = 60; self.tableView.rowHeight = UITableViewAutomaticDimension; self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; [self.tableView setSeparatorInset:UIEdgeInsetsZero]; i = 1; self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(refreshList)]; self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)]; [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]]; self.navigationController.navigationBar.barTintColor = [UIColor colorWithHexString:@"#333333"] ; UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom]; btn.frame = CGRectMake(0, 0, 40, 40); [btn setImage:[UIImage imageNamed:@"fanhui1"] forState:UIControlStateNormal]; btn.imageEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0); [btn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:btn]; UIBarButtonItem *nagetiveSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; nagetiveSpacer.width = -12;//这个值可以根据自己需要自己调整 self.navigationItem.leftBarButtonItems = @[nagetiveSpacer, leftItem]; self.view.backgroundColor = [UIColor blackColor]; } -(void)backClick{ [self.navigationController popViewControllerAnimated:YES]; } - (void)viewWillAppear:(BOOL)animated{ [self getPingLun:[NSString stringWithFormat:@"%d",i]]; } -(void)refreshList{ i = 1; [self.pingLunArray removeAllObjects]; [self getPingLun:[NSString stringWithFormat:@"%d",i]]; } - (void)loadMoreData{ i++; [self getPingLun:[NSString stringWithFormat:@"%d",i]]; } - (void)getPingLun:(NSString*)index{ NSString *str = [NSString stringWithFormat:@"%@modelInfo?action=findmodelprivatelimit&privatePk=%@&index=%@&size=10",imageURl,_model.privatepk,index]; [[AHHttpManager sharedManager]POST:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] parameters:nil success:^(id responseObject) { if ([[responseObject objectForKey:@"msg"]isEqualToString:@"success"]) { NSArray *data = responseObject[@"data"]; NSArray * array = [PingLunModel arrayOfModelsFromDictionaries:data]; [self.pingLunArray addObjectsFromArray:array]; [self.tableView reloadData]; NSString *number = responseObject[@"count"]; NSInteger num = [number integerValue]; [self.tableView.mj_header endRefreshing]; if (num == self.pingLunArray.count) { [self.tableView.mj_footer endRefreshingWithNoMoreData]; }else{ [self.tableView.mj_footer endRefreshing]; } }else{ [MBProgressHUD showTextHUD:@"超时" inView:self.view hideAfterDelay:1]; } } failure:^(NSError *error) { NSLog(@"error = %@",error); [MBProgressHUD showTextHUD:@"超时" inView:self.view hideAfterDelay:1]; }]; } #pragma mark - deleDate - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 2; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ if (section==0) { return 1; }else{ return self.pingLunArray.count; } } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ if (indexPath.section==0) { if (_model.iteminfo.count==0) { DetailOnlyTextCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DetailOnlyTextCell"]; if(!cell){ cell = [[[UINib nibWithNibName:@"DetailOnlyTextCell" bundle:nil]instantiateWithOwner:self options:nil]lastObject]; cell.model = _model; cell.name = _name; cell.icon = _iconImage; cell.delegate = self; cell.selectionStyle = UITableViewCellSelectionStyleNone; } return cell; }else if(_model.iteminfo.count==1||_model.iteminfo.count==2){ DetailOneImageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DetailOneImageCell"]; if(!cell){ cell = [[[UINib nibWithNibName:@"DetailOneImageCell" bundle:nil]instantiateWithOwner:self options:nil]lastObject]; cell.model = _model; cell.name = _name; cell.icon = _iconImage; cell.delegate = self; cell.selectionStyle = UITableViewCellSelectionStyleNone; } return cell; }else if (_model.iteminfo.count==3||_model.iteminfo.count==4){ DetailFourImageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DetailFourImageCell"]; if(!cell){ cell = [[[UINib nibWithNibName:@"DetailFourImageCell" bundle:nil]instantiateWithOwner:self options:nil]lastObject]; cell.model = _model; cell.name = _name; cell.icon = _iconImage; cell.delegate = self; cell.selectionStyle = UITableViewCellSelectionStyleNone; } return cell; } }else{ PingLunCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PingLunCell"]; if(!cell){ cell = [[[UINib nibWithNibName:@"PingLunCell" bundle:nil]instantiateWithOwner:self options:nil]lastObject]; cell.model = [self.pingLunArray objectAtIndex:indexPath.row]; cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.delegate = self; } return cell; } return nil; } -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ if(section==1){ return 10; } return 0.00000001; } #pragma mark 删除delegate -(void)deletePingLun:(NSString*)pk{ UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:nil message:@"确定要删除该评论" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]; UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { [MBProgressHUD showHUDAddedTo:self.view animated:YES]; NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:pk,@"modelprivatediscusspk",_model.privatepk,@"privatepk", nil]; [YanCNetWorkManager requestPostWithURLStr:Url_deletePinglun(PublicUrl) parameters:dic finish:^(id dataDic) { [MBProgressHUD hideHUDForView:self.view animated:YES]; [self refreshList]; }enError:^(NSError *error) { [MBProgressHUD hideHUDForView:self.view animated:YES]; }]; }]; [alertVc addAction:cancelAction]; [alertVc addAction:sureAction]; [self presentViewController:alertVc animated:YES completion:nil]; } - (void)delPrivate:(NSString *)pk{ UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:nil message:@"确定要删除该动态" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]; UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { [MBProgressHUD showHUDAddedTo:self.view animated:YES]; NSString *str = [NSString stringWithFormat:@"%@model?action=doRemoveModelPrivate&privatepk=%@",imageURl,pk]; [[AHHttpManager sharedManager]POST:str parameters:nil success:^(id responseObject) { [MBProgressHUD showHUDAddedTo:self.view animated:YES]; if ([[responseObject objectForKey:@"msg"]isEqualToString:@"success"]) { [self.navigationController popViewControllerAnimated:YES]; }else{ } } failure:^(NSError *error) { NSLog(@"error = %@",error); [MBProgressHUD showHUDAddedTo:self.view animated:YES]; }]; }]; [alertVc addAction:cancelAction]; [alertVc addAction:sureAction]; [self presentViewController:alertVc animated:YES completion:nil]; } -(void)clickImage:(PrivateModel *)model andNum:(int)num{ ImageViewController *ImgVc = [[ImageViewController alloc]init]; ImgVc.model = model; if (model.iteminfo.count==3) { if (num==3) { num=2; } } ImgVc.i = num; ImgVc.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:ImgVc animated:YES]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end