MyMsgVC.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. //
  2. #import "MyMsgVC.h"
  3. #import "STSegView.h"
  4. #import "STCell.h"
  5. #import "TopicVC.h"
  6. @interface MyMsgVC ()<UITableViewDataSource,UITableViewDelegate,STSegViewDelegate>
  7. {
  8. /**左右table。tag分别为0,2
  9. */
  10. UITableView *myTableView,* myTableView2;
  11. int currentPage,currentPage2;
  12. NSMutableArray* models,*models2;
  13. /**每次下载后。就判断.
  14. 如果cnt为0就显示。否则隐藏
  15. */
  16. UIView* placeHolder,* placeHolder2;
  17. STSegView* segV;
  18. UIScrollView* scroll;
  19. }
  20. @end
  21. @implementation MyMsgVC
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. [self myInit];
  25. [MBProgressHUD showLoadToView:self.view];
  26. [self getMessageInfos];
  27. [self getMyMessagesOnFavAndPoints];
  28. }
  29. - (void)didReceiveMemoryWarning {
  30. [super didReceiveMemoryWarning];
  31. }
  32. -(void)viewDidAppear:(BOOL)animated
  33. {
  34. [super viewDidAppear:animated];
  35. }
  36. #pragma mark -
  37. -(void)myInit
  38. {
  39. [self.view setBackgroundColor:backGroundColor];
  40. [self setTitle:@"消息"];
  41. if (_isNotification == NO)
  42. {
  43. //正常状态要dismiss回去
  44. [self configNavigationBar];
  45. }
  46. else
  47. {
  48. //推送状态 要将根视图变回去
  49. UIBarButtonItem* backBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"question_pre_checked_icon.png"] style:UIBarButtonItemStylePlain target:self action:@selector(dismissNavgation)];
  50. [backBtn setTintColor:defGreen];
  51. self.navigationController.navigationBar.translucent = NO;
  52. [self.navigationItem setLeftBarButtonItem:backBtn];
  53. }
  54. currentPage = currentPage2 = 1;
  55. models = [NSMutableArray array];
  56. models2 = [NSMutableArray array];
  57. CGFloat x,y,w,h;
  58. x = y =0;
  59. w = kSize.width;
  60. h = 45;
  61. //自定义分段显示控件
  62. segV = [[STSegView alloc] initWithFrame:CGRectMake(x, y, w, h)];
  63. [segV addSelfViewWithRect:CGRectMake(0, h-1, kSize.width, 1) Color:KlineColor];
  64. y = h;
  65. [segV setTitles:@[@"回复与赞",@"系统消息"]];
  66. [segV setDelegate:self];
  67. [segV setBackgroundColor:[UIColor whiteColor]];
  68. [self.view addSubview:segV];
  69. scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, y, kSize.width, kSize.height - y - kNavOffSet) ];
  70. scroll.showsHorizontalScrollIndicator = NO;
  71. [self.view addSubview:scroll];
  72. [scroll setContentSize:CGSizeMake(kSize.width*2, 0)];
  73. [scroll setTag:1];
  74. [scroll setPagingEnabled:YES];
  75. [scroll setDelegate:self];
  76. UITableView* tv ;
  77. tv = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, kSize.height - y - kNavOffSet) style:UITableViewStyleGrouped];
  78. tv.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, .1, .1)];
  79. tv.estimatedSectionHeaderHeight = 0;
  80. [scroll addSubview:tv];
  81. myTableView = tv;
  82. [tv setBackgroundColor:backGroundColor];
  83. [tv setTableFooterView:[UIView new]];
  84. [tv setTag:0];
  85. tv = [[UITableView alloc] initWithFrame:CGRectMake(kSize.width, 0, kSize.width, kSize.height - y - kNavOffSet) style:UITableViewStyleGrouped];
  86. tv.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, .1, .1)];
  87. tv.estimatedSectionHeaderHeight = 0;
  88. [scroll addSubview:tv];
  89. myTableView2 = tv;
  90. [tv setBackgroundColor:backGroundColor];
  91. [tv setTableFooterView:[UIView new]];
  92. [tv setTag:2];
  93. if (_isNotification == YES)
  94. {
  95. //如果推送 默认进入系统消息
  96. segV.selectedIndex = 1;
  97. [scroll setContentOffset:CGPointMake(kSize.width, 0)];
  98. }
  99. //placeHolder
  100. y = 0;
  101. UIView* vi = [[UIView alloc] initWithFrame:CGRectMake(0, y, kSize.width, kSize.height - y - kNavOffSet)];
  102. [scroll addSubview:vi];
  103. vi.hidden = NO;
  104. placeHolder = vi;
  105. w = h = kSize.width/3.0;
  106. x = y = w;
  107. UIImageView* iv = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, w, h)];
  108. [iv setImage:[UIImage imageNamed:@"community4.png"]];
  109. [iv setContentMode:UIViewContentModeScaleAspectFit];
  110. [placeHolder addSubview:iv];
  111. y += h + 20;
  112. x = 0;
  113. w = kSize.width;
  114. h = 40;
  115. UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, w, h)];
  116. [label setText:@"您暂无相关消息~"];
  117. [label setTextAlignment:NSTextAlignmentCenter];
  118. [label setTextColor:contentTextColor];
  119. [placeHolder addSubview:label];
  120. //placeHolder2
  121. y = 0;
  122. vi = [[UIView alloc] initWithFrame:CGRectMake(kSize.width, y, kSize.width, kSize.height - y - kNavOffSet)];
  123. [scroll addSubview:vi];
  124. vi.hidden = NO;
  125. placeHolder2 = vi;
  126. w = h = kSize.width/3.0;
  127. x = y = w;
  128. iv = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, w, h)];
  129. [iv setImage:[UIImage imageNamed:@"community4.png"]];
  130. [iv setContentMode:UIViewContentModeScaleAspectFit];
  131. [placeHolder2 addSubview:iv];
  132. y += h + 20;
  133. x = 0;
  134. w = kSize.width;
  135. h = 40;
  136. label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, w, h)];
  137. [label setText:@"您暂无相关消息~"];
  138. [label setTextAlignment:NSTextAlignmentCenter];
  139. [label setTextColor:contentTextColor];
  140. [placeHolder2 addSubview:label];
  141. }
  142. -(void)dismissNavgation
  143. {
  144. //推送过来 返回主页面
  145. [myDelegate gotoLoad];
  146. }
  147. -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
  148. {
  149. if ( 1 == scrollView.tag) {
  150. CGPoint off = scroll.contentOffset;
  151. [segV setSelectedIndex:(off.x / kSize.width)];
  152. return;
  153. }
  154. CGPoint off = scrollView.contentOffset;
  155. if (scrollView.contentSize.height - off.y - scrollView.frame.size.height < 1) {
  156. [scrollView setContentOffset:CGPointMake(off.x, off.y - 10) animated:YES];
  157. //NSLog(@"AT bottom");
  158. [MBProgressHUD showLoadToView:self.view];
  159. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  160. if (0 == scrollView.tag) {
  161. [self getMyMessagesOnFavAndPoints];
  162. }
  163. if (2 == scrollView.tag) {
  164. [self getMessageInfos];
  165. }
  166. });
  167. }
  168. }
  169. -(void)didSelectedIndex:(NSInteger)index
  170. {
  171. [scroll setContentOffset:CGPointMake(kSize.width*index, 0) animated:YES];
  172. }
  173. #pragma mark -
  174. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  175. {
  176. return .1;
  177. }
  178. -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  179. {
  180. UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 10)];
  181. [v setBackgroundColor:[UIColor colorWithWhite:.96 alpha:1]];
  182. return v;
  183. }
  184. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  185. {
  186. return 10;
  187. }
  188. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(nonnull NSIndexPath *)indexPath
  189. {
  190. if (tableView.tag == 0){
  191. return 70;
  192. }else{
  193. NSDictionary *dic = models2[indexPath.section];
  194. NSString *str = dic[@"CONTENT"];
  195. CGFloat height = [str heightForWid:kSize.width - 100 Font:18];
  196. if (height < 60.0) {
  197. height = 60;
  198. }
  199. return height + 50;
  200. }
  201. }
  202. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  203. {
  204. return 1;
  205. }
  206. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  207. {
  208. if ( 0 == tableView.tag) {
  209. return models.count;
  210. }else{
  211. return models2.count;
  212. }
  213. }
  214. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  215. {
  216. STCell* cell = [STCell cellForTableView:tableView];
  217. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  218. if (0 == tableView.tag) {
  219. //评论点赞
  220. [cell setModelReply:models[indexPath.section]];
  221. }else{
  222. //消息
  223. [cell setModel:models2[indexPath.section]];
  224. }
  225. return cell;
  226. }
  227. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  228. {
  229. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  230. if (0 == tableView.tag) {
  231. NSDictionary *obj = models[indexPath.section];
  232. TopicVC* vc = [[TopicVC alloc] init];
  233. [vc setTopicId:obj[@"TOPICID"]];
  234. [self navPushHideTabbarToVC:vc];
  235. }
  236. }
  237. #pragma mark - 这是异步加载 只不过刚进来是在主线程中的异步加载
  238. /**系统消息
  239. */
  240. -(void)getMessageInfos
  241. {
  242. if (![Util connectedToNetWork]) {
  243. showMsgUnconnect();
  244. return;
  245. }
  246. NSMutableArray *arr=[NSMutableArray array];
  247. NSString *idStr = defUser.userDict[@"id"];
  248. if (!idStr || [idStr isEqualToString:@""]) {
  249. return;
  250. }
  251. [arr addPro:@"user" Value:defUser.userDict[@"id"]];
  252. [arr addPro:@"msgType" Value:@""];
  253. [arr addPro:@"userType" Value:@"1"];
  254. [arr addPro:@"isPage" Value:@"1"];
  255. [arr addPro:@"pageSize" Value:@"10"];
  256. [arr addPro:@"currentPage" Value:[NSString stringWithFormat:@"%d",currentPage2]];
  257. NSString* method = @"getMessageInfos";
  258. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
  259. [MBProgressHUD hideHUDForView:self.view];
  260. //NSLog(@"getMessageInfos系统----%@",dict);
  261. if (!dict) {
  262. ShowMsgFailed();
  263. return;
  264. }
  265. if ( [dict[@"code"] isEqualToString:@"1"]) {
  266. ShowMsg(dict[@"body"]);
  267. return;
  268. }
  269. NSArray* json = dict[@"body"];
  270. if (json.count > 0) {
  271. [models2 addObjectsFromArray:json];
  272. currentPage2 ++;
  273. }else{
  274. if (currentPage2 > 1) {
  275. ShowMsg(@"已加载全部");
  276. }
  277. }
  278. // NSLog(@"models2cnt------%d",(int)models2.count);
  279. if (models2.count < 1) {
  280. placeHolder2.hidden = NO;
  281. }else{
  282. placeHolder2.hidden = YES;
  283. [myTableView2 setDelegate:self];
  284. [myTableView2 setDataSource:self];
  285. [myTableView2 reloadData];
  286. }
  287. }];
  288. }
  289. /**回复与赞
  290. */
  291. -(void)getMyMessagesOnFavAndPoints
  292. {
  293. if (![Util connectedToNetWork]) {
  294. showMsgUnconnect();
  295. return;
  296. }
  297. NSMutableArray *arr=[NSMutableArray array];
  298. [arr addPro:@"user" Value:defUser.userDict[@"id"]];
  299. [arr addPro:@"isPage" Value:@"1"];
  300. [arr addPro:@"pageSize" Value:@"10"];
  301. [arr addPro:@"currentPage" Value:[NSString stringWithFormat:@"%d",currentPage]];
  302. NSString* method = @"getMyMessagesOnFavAndPoints";
  303. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
  304. [MBProgressHUD hideHUDForView:self.view];
  305. if (!dict) {
  306. ShowMsgFailed();
  307. return;
  308. }
  309. if ( [dict[@"code"] isEqualToString:@"1"]) {
  310. ShowMsg(dict[@"body"]);
  311. return;
  312. }
  313. NSArray* json = dict[@"body"];
  314. if (json.count > 0) {
  315. [models addObjectsFromArray:json];
  316. currentPage ++;
  317. }else{
  318. //一定要加上这个判断 要不然 这个展示信息在主线程 请求也在主线程 会卡塞线程的
  319. if (currentPage > 1) {
  320. ShowMsg(@"已加载全部");
  321. }
  322. }
  323. if (models.count < 1) {
  324. placeHolder.hidden = NO;
  325. }else{
  326. placeHolder.hidden = YES;
  327. [myTableView setDelegate:self];
  328. [myTableView setDataSource:self];
  329. [myTableView reloadData];
  330. }
  331. }];
  332. }
  333. @end