123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- //
- // MyMsgVC.m
- // jiaPeiC
- //
- // Created by apple on 15/12/17.
- // Copyright © 2015年 JCZ. All rights reserved.
- //
- #import "MyMsgVC.h"
- #import "MsgListCell.h"
- #import "UIImageView+WebCache.h"
- @interface MyMsgVC () <UITableViewDataSource,UITableViewDelegate>
- {
- NSArray *models;
- UITableView *myTableView;
- HolderView *holderV;
- int currentPage;
- }
- @end
- @implementation MyMsgVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self myInit];
- [self getMessageInfos];
- }
- -(void)viewWillDisappear:(BOOL)animated
- {
- //所有有请求的页面都要加
- [super viewWillDisappear:animated];
- RemoveHUD();
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
- #pragma mark -
- -(void)myInit
- {
- self.title = @"我的消息";
-
- if (_isNotification == NO)
- {
- //正常状态
- [self configNavBar];
- }
- else
- {
- //推送状态 要将根视图变回去
- UIBarButtonItem* backBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back.png"] style:UIBarButtonItemStylePlain target:self action:@selector(dismissNavgation)];
- [backBtn setTintColor:defGreen];
- // self.navigationController.navigationBar.translucent = NO;
- [self.navigationItem setLeftBarButtonItem:backBtn];
- }
-
- currentPage = 1;
- myTableView = [[UITableView alloc] initWithFrame:kFrame];
- [myTableView setDelegate:self];
- [myTableView setDataSource:self];
- myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- [self.view addSubview:myTableView];
- holderV = [[HolderView alloc] initWithFrame:kFrame];
- holderV.y = kNavOffSet;
- [holderV freshBlock:^{
- [self getMessageInfos];
- }];
- [self addV:holderV];
- }
- -(void)dismissNavgation
- {
- //推送过来 返回主页面
- [myDelegate gotoLoad];
- }
- #pragma mark -
- - (void)getMessageInfos
- {
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- NSMutableArray *arr=[NSMutableArray array];
- [arr addPro:@"user" Value:defUser.sfzmhm];
- [arr addPro:@"msgType" Value:@""];
- [arr addPro:@"userType" Value:@"2"];
- [arr addPro:@"isPage" Value:@"1"];
- [arr addPro:@"pageSize" Value:@"10"];
- [arr addPro:@"currentPage" Value:[NSString stringWithFormat:@"%d",currentPage]];
-
- NSString* method = @"getMessageInfos";
- ShowHUD();
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
- RemoveHUD();
-
- //NSLog(@"root---->%@",root);
- if (!root) {
- ShowMsgFailed();
- [holderV setHidden:NO];
- return ;
- }
- if ([root[@"code"] isEqualToString:@"1"]) {
- ShowMsgFailed();
- [holderV setHidden:NO];
- return;
- }
- models = root[@"body"];
- if (models.count > 0) {
- currentPage ++;
- [myTableView reloadData];
- [holderV setHidden:YES];
- }else{
-
- [holderV setHidden:NO];
- }
-
- }];
- }
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return models.count;
- }
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- MsgListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
- if (cell == nil)
- {
- cell = [[MsgListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- }
-
- NSDictionary *model = models[indexPath.row];
- [cell.dateBtn setTitle:model[@"CRDATE"] textColor:[UIColor whiteColor] font:15 fotState:UIControlStateNormal];
-
- NSString *str = model[@"PHOTO"];
- if (!str) {
- str = @"";
- }
- [cell.headImgView sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"noHeadImg.png"]];
-
- NSString *contentString = model[@"CONTENT"];
- cell.messageContentLabel.text = contentString;
-
- //重新设置文本和气泡的大小
- float newHeight = [self getRectWithPostContent:contentString];
- CGRect newRect = cell.backImageView.frame;
- newRect.size.height = newHeight + 10;
- cell.backImageView.frame = newRect;
-
- newRect = cell.messageContentLabel.frame;
- newRect.size.height = newHeight;
- cell.messageContentLabel.frame = newRect;
-
- return cell;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- NSDictionary * dic = models[indexPath.row];
- NSString * content = dic[@"CONTENT"];
- return [self getRectWithPostContent:content] + 50;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
- {
- return .1;
- }
- -(float)getRectWithPostContent:(NSString *)content
- {
- CGRect rect = [content boundingRectWithSize:CGSizeMake(kSize.width - 155, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont scaleSize:17] } context:nil];
-
- //整数位取整加1或者等于自己
- float height = ceilf(rect.size.height);
- //得出的高是文本的高 文本所在的label距离cell的边框有一定的距离 所以加上20
- return height+ 30;
- }
- @end
|