You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

201 lines
7.3 KiB

//
// CallMessageViewController.m
// tongxin
//
// Created by ecell on 2021/6/25.
// Copyright © 2021 xTT. All rights reserved.
//
#import "CallMessageViewController.h"
#import "CMessage.h"
#import "MessageTableViewCell.h"
@interface CallMessageViewController ()
@property (nonatomic,strong) NSMutableArray *listDataSoure;
@property (nonatomic,strong) NSMutableArray *dateArr;
@property (nonatomic,assign) int page;
@end
@implementation CallMessageViewController
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
//[self loadMoreDataWithCMessage:[NSNumber numberWithInt:_page]];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.zx_hideBaseNavBar = YES;
_page = 1;
self.myTableView.frame = CGRectMake(-4, 0, SWIDTH+8, self.myTableView.bounds.size.height-60);
self.view.backgroundColor = KKBackgroundGrey;
[UICommon setTavleViewlink:self.myTableView distance:16];
[self.view addSubview:self.myTableView];
// Do any additional setup after loading the view.
self.listDataSoure = [[NSMutableArray alloc] init];
self.dateArr = [[NSMutableArray alloc] init];
WEAKSELF
self.myTableView.mj_footer = [MJRefreshBackGifFooter footerWithRefreshingBlock:^{
[weakSelf loadMoreDataWithCMessage:[NSNumber numberWithInt:_page]];
}];
[self.myTableView registerNib:[UINib nibWithNibName:@"MessageTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"MessageTableViewCellID"];
//[self.myTableView.mj_footer beginRefreshing];
[self loadMoreDataWithCMessage:[NSNumber numberWithInt:_page]];
self.myTableView.tableFooterView = [[UIView alloc] init];
// iOS 11 系统 tableView 会自动调整高度 在 Gounp 模式下 头部的高度会有问题 ,需要对 预设的高度设置为0
self.myTableView.estimatedRowHeight = 0;
self.myTableView.estimatedSectionHeaderHeight = 0;
self.myTableView.estimatedSectionFooterHeight = 0;
}
//MARK :刪除方法
-(void)deletAction{
WEAKSELF
CommonPopView *popView = [CommonPopView new];
[popView subPopView:popViewType_binding PopTitle:@"注意" PopText:@"确认要清空提醒消息?" okTouchBlock:^{
[CMessage delectTrackWithMessageIds:nil success:^(id responseObject) {
[weakSelf.myDataSource removeAllObjects];
[weakSelf.listDataSoure removeAllObjects];
[weakSelf.dateArr removeAllObjects];
[weakSelf loadMoreDataWithCMessage:@1];
xLog(@"删除记录成功!")
} failure:^{
[SVProgressHUD showSuccessWithStatus:@"删除记录失败,请稍后重试..."];
} ];
}];
}
- (void)loadMoreDataWithCMessage:(NSNumber *)page {
WEAKSELF
[CMessage getCallMessageWithPage:page success:^(NSMutableArray * _Nonnull arr) {
if([page intValue] == 1){
[weakSelf.listDataSoure removeAllObjects];
[weakSelf.dateArr removeAllObjects];
[weakSelf.myDataSource removeAllObjects];
}
[weakSelf.listDataSoure addObjectsFromArray:arr];
_page++;
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
[weakSelf.listDataSoure enumerateObjectsUsingBlock:^(CMessage *_Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSDate *date = [NSDate dateWithTimeIntervalSince1970:[obj.t doubleValue]];
NSString *dateStr = [myHelper getDateFormatWithStr:@"yyyy-MM-dd" date:date];
NSMutableArray *arr = dic[dateStr];
if (!arr) {
arr = [NSMutableArray array];
}
[arr addObject:obj];
[dic setObject:arr forKey:dateStr];
if (![weakSelf.dateArr containsObject:dateStr]) {
[weakSelf.dateArr addObject:dateStr];
}
}];
[weakSelf.myDataSource removeAllObjects];
[weakSelf.dateArr enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
[weakSelf.myDataSource addObject:dic[obj]];
}];
[weakSelf.myTableView reloadData];
if ([[weakSelf.myDataSource firstObject] count] == 0){
weakSelf.navigationItem.rightBarButtonItem = nil;;
}
[weakSelf.myTableView.mj_footer endRefreshing];
} failure:^(NSError * _Nonnull error) {
if (!error) {
}
[weakSelf.myTableView.mj_footer endRefreshing];
}];
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView
editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewCellEditingStyleNone;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 40;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
[[UILabel appearanceWhenContainedInInstancesOfClasses:@[[UITableViewHeaderFooterView class]]] setTextAlignment:NSTextAlignmentCenter];
//[[UILabel appearanceWhenContainedInInstancesOfClasses:@[[UITableViewHeaderFooterView class]]] setFont:[UIFont systemFontOfSize:12.0 weight:UIFontWeightThin]];
return self.dateArr[section];
}
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section
{
if([view isKindOfClass:[UITableViewHeaderFooterView class]])
{
UITableViewHeaderFooterView *tableViewHeaderFooterView = (UITableViewHeaderFooterView *) view;
tableViewHeaderFooterView.textLabel.textAlignment = NSTextAlignmentCenter;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
CMessage *cMessage = self.myDataSource[indexPath.section][indexPath.row];
NSString *str = [NSString stringWithFormat:@"【%@】(%@)给您视频来电了",cMessage.name,cMessage.i];
return [self getLineHeight:str withWidth:SWIDTH*(280.0/320) withFont:[UIFont systemFontOfSize:13]];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
CMessage *cMessage = self.myDataSource[indexPath.section][indexPath.row];
MessageTableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:@"MessageTableViewCellID" forIndexPath:indexPath];
NSDate *date = [NSDate dateWithTimeIntervalSince1970:[cMessage.t doubleValue]];
cell.timeLabel.text = [myHelper getDateFormatWithStr:@"HH:mm" date:date]; //时间
cell.messageLabel.text = [NSString stringWithFormat:@"【%@】(%@)给您视频来电了",cMessage.name,cMessage.i];;
cell.readLabel.hidden = YES;
cell.aTitleLabel.text = @"视频来电";
return cell;
}
- (CGFloat)getLineHeight:(NSString *)string withWidth:(CGFloat)width withFont:(UIFont *)font{
UILabel *label = [[UILabel alloc]init];
label.numberOfLines = 0;
label.lineBreakMode = NSLineBreakByWordWrapping;
label.textAlignment = NSTextAlignmentLeft;
label.text = string;
label.font = font;
CGSize labelSize = [label sizeThatFits:CGSizeMake(width, MAXFLOAT)];
CGFloat height = ceil(labelSize.height) + 1 + 34 + 10 +8;
//换行符的 行数
NSUInteger number = [[string componentsSeparatedByString:@"\n"] count];
if(number > 1){
height += (number-1) * 21;
}
if(height < 66){
height = 66;
}
return height;
}
@end