MyMsgVC.m 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. //
  2. // MyMsgVC.m
  3. // jiaPeiC
  4. //
  5. // Created by apple on 15/12/17.
  6. // Copyright © 2015年 JCZ. All rights reserved.
  7. //
  8. #import "MyMsgVC.h"
  9. #import "MsgListCell.h"
  10. #import "UIImageView+WebCache.h"
  11. @interface MyMsgVC () <UITableViewDataSource,UITableViewDelegate>
  12. {
  13. NSArray *models;
  14. UITableView *myTableView;
  15. HolderView *holderV;
  16. int currentPage;
  17. }
  18. @end
  19. @implementation MyMsgVC
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. [self myInit];
  23. [self getMessageInfos];
  24. }
  25. -(void)viewWillDisappear:(BOOL)animated
  26. {
  27. //所有有请求的页面都要加
  28. [super viewWillDisappear:animated];
  29. RemoveHUD();
  30. }
  31. - (void)didReceiveMemoryWarning {
  32. [super didReceiveMemoryWarning];
  33. }
  34. #pragma mark -
  35. -(void)myInit
  36. {
  37. self.title = @"我的消息";
  38. if (_isNotification == NO)
  39. {
  40. //正常状态
  41. [self configNavBar];
  42. }
  43. else
  44. {
  45. //推送状态 要将根视图变回去
  46. UIBarButtonItem* backBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back.png"] style:UIBarButtonItemStylePlain target:self action:@selector(dismissNavgation)];
  47. [backBtn setTintColor:defGreen];
  48. // self.navigationController.navigationBar.translucent = NO;
  49. [self.navigationItem setLeftBarButtonItem:backBtn];
  50. }
  51. currentPage = 1;
  52. myTableView = [[UITableView alloc] initWithFrame:kFrame];
  53. [myTableView setDelegate:self];
  54. [myTableView setDataSource:self];
  55. myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  56. [self.view addSubview:myTableView];
  57. holderV = [[HolderView alloc] initWithFrame:kFrame];
  58. holderV.y = kNavOffSet;
  59. [holderV freshBlock:^{
  60. [self getMessageInfos];
  61. }];
  62. [self addV:holderV];
  63. }
  64. -(void)dismissNavgation
  65. {
  66. //推送过来 返回主页面
  67. [myDelegate gotoLoad];
  68. }
  69. #pragma mark -
  70. - (void)getMessageInfos
  71. {
  72. if (![Util connectedToNetWork]) {
  73. showMsgUnconnect();
  74. return;
  75. }
  76. NSMutableArray *arr=[NSMutableArray array];
  77. [arr addPro:@"user" Value:defUser.sfzmhm];
  78. [arr addPro:@"msgType" Value:@""];
  79. [arr addPro:@"userType" Value:@"2"];
  80. [arr addPro:@"isPage" Value:@"1"];
  81. [arr addPro:@"pageSize" Value:@"10"];
  82. [arr addPro:@"currentPage" Value:[NSString stringWithFormat:@"%d",currentPage]];
  83. NSString* method = @"getMessageInfos";
  84. ShowHUD();
  85. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  86. RemoveHUD();
  87. //NSLog(@"root---->%@",root);
  88. if (!root) {
  89. ShowMsgFailed();
  90. [holderV setHidden:NO];
  91. return ;
  92. }
  93. if ([root[@"code"] isEqualToString:@"1"]) {
  94. ShowMsgFailed();
  95. [holderV setHidden:NO];
  96. return;
  97. }
  98. models = root[@"body"];
  99. if (models.count > 0) {
  100. currentPage ++;
  101. [myTableView reloadData];
  102. [holderV setHidden:YES];
  103. }else{
  104. [holderV setHidden:NO];
  105. }
  106. }];
  107. }
  108. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  109. {
  110. return models.count;
  111. }
  112. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  113. {
  114. MsgListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  115. if (cell == nil)
  116. {
  117. cell = [[MsgListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
  118. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  119. }
  120. NSDictionary *model = models[indexPath.row];
  121. [cell.dateBtn setTitle:model[@"CRDATE"] textColor:[UIColor whiteColor] font:15 fotState:UIControlStateNormal];
  122. NSString *str = model[@"PHOTO"];
  123. if (!str) {
  124. str = @"";
  125. }
  126. [cell.headImgView sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"noHeadImg.png"]];
  127. NSString *contentString = model[@"CONTENT"];
  128. cell.messageContentLabel.text = contentString;
  129. //重新设置文本和气泡的大小
  130. float newHeight = [self getRectWithPostContent:contentString];
  131. CGRect newRect = cell.backImageView.frame;
  132. newRect.size.height = newHeight + 10;
  133. cell.backImageView.frame = newRect;
  134. newRect = cell.messageContentLabel.frame;
  135. newRect.size.height = newHeight;
  136. cell.messageContentLabel.frame = newRect;
  137. return cell;
  138. }
  139. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  140. {
  141. NSDictionary * dic = models[indexPath.row];
  142. NSString * content = dic[@"CONTENT"];
  143. return [self getRectWithPostContent:content] + 50;
  144. }
  145. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  146. {
  147. return .1;
  148. }
  149. -(float)getRectWithPostContent:(NSString *)content
  150. {
  151. CGRect rect = [content boundingRectWithSize:CGSizeMake(kSize.width - 155, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont scaleSize:17] } context:nil];
  152. //整数位取整加1或者等于自己
  153. float height = ceilf(rect.size.height);
  154. //得出的高是文本的高 文本所在的label距离cell的边框有一定的距离 所以加上20
  155. return height+ 30;
  156. }
  157. @end