DetailOnlyTextViewController.m 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. //
  2. // DetailOnlyTextViewController.m
  3. // model
  4. //
  5. // Created by MUMEI on 2018/8/6.
  6. // Copyright © 2018年 Mine. All rights reserved.
  7. //
  8. #import "DetailOnlyTextViewController.h"
  9. #import "ImageViewController.h"
  10. #import "DetailOnlyTextCell.h"
  11. #import "DetailOneImageCell.h"
  12. #import "DetailFourImageCell.h"
  13. #import "PingLunCell.h"
  14. @interface DetailOnlyTextViewController ()<DetailOnlyTextDelegate,DetailOneImageDelegate,DetailFourImageDelegate,PingLunDelegate>
  15. @property (weak, nonatomic) IBOutlet UITableView *tableView;
  16. @property (strong, nonatomic) NSMutableArray *pingLunArray;
  17. @end
  18. @implementation DetailOnlyTextViewController
  19. {
  20. int i;
  21. }
  22. - (NSMutableArray *)pingLunArray {
  23. if (!_pingLunArray) {
  24. _pingLunArray = [NSMutableArray arrayWithCapacity:0];
  25. }
  26. return _pingLunArray;
  27. }
  28. - (void)viewDidLoad {
  29. [super viewDidLoad];
  30. self.tableView.estimatedRowHeight = 60;
  31. self.tableView.rowHeight = UITableViewAutomaticDimension;
  32. self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  33. [self.tableView setSeparatorInset:UIEdgeInsetsZero];
  34. i = 1;
  35. self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(refreshList)];
  36. self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
  37. [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
  38. self.navigationController.navigationBar.barTintColor = [UIColor colorWithHexString:@"#333333"] ;
  39. UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
  40. btn.frame = CGRectMake(0, 0, 40, 40);
  41. [btn setImage:[UIImage imageNamed:@"fanhui1"] forState:UIControlStateNormal];
  42. btn.imageEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
  43. [btn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
  44. UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
  45. UIBarButtonItem *nagetiveSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
  46. nagetiveSpacer.width = -12;//这个值可以根据自己需要自己调整
  47. self.navigationItem.leftBarButtonItems = @[nagetiveSpacer, leftItem];
  48. self.view.backgroundColor = [UIColor blackColor];
  49. }
  50. -(void)backClick{
  51. [self.navigationController popViewControllerAnimated:YES];
  52. }
  53. - (void)viewWillAppear:(BOOL)animated{
  54. [self getPingLun:[NSString stringWithFormat:@"%d",i]];
  55. }
  56. -(void)refreshList{
  57. i = 1;
  58. [self.pingLunArray removeAllObjects];
  59. [self getPingLun:[NSString stringWithFormat:@"%d",i]];
  60. }
  61. - (void)loadMoreData{
  62. i++;
  63. [self getPingLun:[NSString stringWithFormat:@"%d",i]];
  64. }
  65. - (void)getPingLun:(NSString*)index{
  66. NSString *str = [NSString stringWithFormat:@"%@modelInfo?action=findmodelprivatelimit&privatePk=%@&index=%@&size=10",imageURl,_model.privatepk,index];
  67. [[AHHttpManager sharedManager]POST:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] parameters:nil success:^(id responseObject) {
  68. if ([[responseObject objectForKey:@"msg"]isEqualToString:@"success"]) {
  69. NSArray *data = responseObject[@"data"];
  70. NSArray * array = [PingLunModel arrayOfModelsFromDictionaries:data];
  71. [self.pingLunArray addObjectsFromArray:array];
  72. [self.tableView reloadData];
  73. NSString *number = responseObject[@"count"];
  74. NSInteger num = [number integerValue];
  75. [self.tableView.mj_header endRefreshing];
  76. if (num == self.pingLunArray.count) {
  77. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  78. }else{
  79. [self.tableView.mj_footer endRefreshing];
  80. }
  81. }else{
  82. [MBProgressHUD showTextHUD:@"超时" inView:self.view hideAfterDelay:1];
  83. }
  84. } failure:^(NSError *error) {
  85. NSLog(@"error = %@",error);
  86. [MBProgressHUD showTextHUD:@"超时" inView:self.view hideAfterDelay:1];
  87. }];
  88. }
  89. #pragma mark - deleDate
  90. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  91. {
  92. return 2;
  93. }
  94. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  95. if (section==0) {
  96. return 1;
  97. }else{
  98. return self.pingLunArray.count;
  99. }
  100. }
  101. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  102. if (indexPath.section==0) {
  103. if (_model.iteminfo.count==0) {
  104. DetailOnlyTextCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DetailOnlyTextCell"];
  105. if(!cell){
  106. cell = [[[UINib nibWithNibName:@"DetailOnlyTextCell" bundle:nil]instantiateWithOwner:self options:nil]lastObject];
  107. cell.model = _model;
  108. cell.name = _name;
  109. cell.icon = _iconImage;
  110. cell.delegate = self;
  111. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  112. }
  113. return cell;
  114. }else if(_model.iteminfo.count==1||_model.iteminfo.count==2){
  115. DetailOneImageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DetailOneImageCell"];
  116. if(!cell){
  117. cell = [[[UINib nibWithNibName:@"DetailOneImageCell" bundle:nil]instantiateWithOwner:self options:nil]lastObject];
  118. cell.model = _model;
  119. cell.name = _name;
  120. cell.icon = _iconImage;
  121. cell.delegate = self;
  122. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  123. }
  124. return cell;
  125. }else if (_model.iteminfo.count==3||_model.iteminfo.count==4){
  126. DetailFourImageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DetailFourImageCell"];
  127. if(!cell){
  128. cell = [[[UINib nibWithNibName:@"DetailFourImageCell" bundle:nil]instantiateWithOwner:self options:nil]lastObject];
  129. cell.model = _model;
  130. cell.name = _name;
  131. cell.icon = _iconImage;
  132. cell.delegate = self;
  133. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  134. }
  135. return cell;
  136. }
  137. }else{
  138. PingLunCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PingLunCell"];
  139. if(!cell){
  140. cell = [[[UINib nibWithNibName:@"PingLunCell" bundle:nil]instantiateWithOwner:self options:nil]lastObject];
  141. cell.model = [self.pingLunArray objectAtIndex:indexPath.row];
  142. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  143. cell.delegate = self;
  144. }
  145. return cell;
  146. }
  147. return nil;
  148. }
  149. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  150. if(section==1){
  151. return 10;
  152. }
  153. return 0.00000001;
  154. }
  155. #pragma mark 删除delegate
  156. -(void)deletePingLun:(NSString*)pk{
  157. UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:nil message:@"确定要删除该评论" preferredStyle:UIAlertControllerStyleAlert];
  158. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
  159. UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  160. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  161. NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:pk,@"modelprivatediscusspk",_model.privatepk,@"privatepk", nil];
  162. [YanCNetWorkManager requestPostWithURLStr:Url_deletePinglun(PublicUrl) parameters:dic finish:^(id dataDic) {
  163. [MBProgressHUD hideHUDForView:self.view animated:YES];
  164. [self refreshList];
  165. }enError:^(NSError *error) {
  166. [MBProgressHUD hideHUDForView:self.view animated:YES];
  167. }];
  168. }];
  169. [alertVc addAction:cancelAction];
  170. [alertVc addAction:sureAction];
  171. [self presentViewController:alertVc animated:YES completion:nil];
  172. }
  173. - (void)delPrivate:(NSString *)pk{
  174. UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:nil message:@"确定要删除该动态" preferredStyle:UIAlertControllerStyleAlert];
  175. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
  176. UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  177. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  178. NSString *str = [NSString stringWithFormat:@"%@model?action=doRemoveModelPrivate&privatepk=%@",imageURl,pk];
  179. [[AHHttpManager sharedManager]POST:str parameters:nil success:^(id responseObject) {
  180. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  181. if ([[responseObject objectForKey:@"msg"]isEqualToString:@"success"]) {
  182. [self.navigationController popViewControllerAnimated:YES];
  183. }else{
  184. }
  185. } failure:^(NSError *error) {
  186. NSLog(@"error = %@",error);
  187. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  188. }];
  189. }];
  190. [alertVc addAction:cancelAction];
  191. [alertVc addAction:sureAction];
  192. [self presentViewController:alertVc animated:YES completion:nil];
  193. }
  194. -(void)clickImage:(PrivateModel *)model andNum:(int)num{
  195. ImageViewController *ImgVc = [[ImageViewController alloc]init];
  196. ImgVc.model = model;
  197. if (model.iteminfo.count==3) {
  198. if (num==3) {
  199. num=2;
  200. }
  201. }
  202. ImgVc.i = num;
  203. ImgVc.hidesBottomBarWhenPushed = YES;
  204. [self.navigationController pushViewController:ImgVc animated:YES];
  205. }
  206. - (void)didReceiveMemoryWarning {
  207. [super didReceiveMemoryWarning];
  208. // Dispose of any resources that can be recreated.
  209. }
  210. @end