| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- //
- // 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 ()<DetailOnlyTextDelegate,DetailOneImageDelegate,DetailFourImageDelegate,PingLunDelegate>
- @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
|