123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- //
- // YOUPAILZIMCommonWordsVC.m
- // MSYOUPAI
- //
- // Created by CY on 2022/3/8.
- // Copyright © 2022 MS. All rights reserved.
- //
- #import "YOUPAILZIMCommonWordsVC.h"
- #import "YOUPAILZCommonWordCell.h"
- #import "YOUPAILCIMTool.h"
- #import "NIMMessageMaker.h"
- @interface YOUPAILZIMCommonWordsVC ()<UITableViewDataSource,UITableViewDelegate>
- @property (nonatomic, weak) UITableView *youpaiptableView;
- @end
- @implementation YOUPAILZIMCommonWordsVC
- - (void)viewWillDisappear:(BOOL)animated{
- [super viewWillDisappear:animated];
- if (self.youpaipreloadDataSourceBlock != nil) {
- self.youpaipreloadDataSourceBlock(self.youpaipdataSource);
- }
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.title = @"聊天常用语";
- self.view.backgroundColor = [UIColor whiteColor];
- [self youpaifinitUI];
- // [self youpaiploadData];
- }
- - (void)youpaifinitFooterView{
- UIView *footerV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 56.0f)];
- self.youpaiptableView.tableFooterView = footerV;
-
- UIButton *transformBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- transformBtn.titleLabel.font = LCFont12;
- transformBtn.layer.cornerRadius = 20.0f;
- transformBtn.clipsToBounds = YES;
- [transformBtn setTitle:@"换一批" forState:0];
- [transformBtn addTarget:self action:@selector(youpaiploadData) forControlEvents:UIControlEventTouchUpInside];
- [transformBtn setTitleColor:LZ7C69FEColor forState:UIControlStateNormal];
- transformBtn.layer.borderColor = LZ7C69FEColor.CGColor;
- transformBtn.layer.borderWidth = 1.0f;
- [footerV addSubview:transformBtn];
- [transformBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.offset(16.0f);
- make.centerX.equalTo(footerV.mas_centerX);
- make.size.mas_offset(CGSizeMake(125.0f, 40.0f));
- }];
- }
- - (void)youpaifinitUI{
- UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
- tableView.dataSource = self;
- tableView.delegate = self;
- tableView.rowHeight = 54.0f;
- tableView.estimatedRowHeight = 54.0f;
- tableView.estimatedSectionHeaderHeight = 0.0f;
- tableView.estimatedSectionFooterHeight = 0.0f;
- tableView.backgroundColor = [UIColor clearColor];
- tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- [self.view addSubview:tableView];
- self.youpaiptableView = tableView;
- [tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.bottom.right.offset(0.0f);
- make.top.offset(NavBarHeight);
- }];
-
- [self youpaifinitFooterView];
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- return self.youpaipdataSource.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- YOUPAILZCommonWordCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(YOUPAILZCommonWordCell.class)];
- if (cell == nil) {
- cell = [[YOUPAILZCommonWordCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(YOUPAILZCommonWordCell.class)];
- }
- [cell youpaifreloadWithModel:self.youpaipdataSource[indexPath.row]];
- return cell;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
- return CGFLOAT_MIN;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
- return CGFLOAT_MIN;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
-
- NIMSession *session = [NIMSession session:self.youpaipto_uid type:NIMSessionTypeP2P];
- NIMMessage *imMessage = [NIMMessageMaker msgWithText:self.youpaipdataSource[indexPath.row].youpaipword];
- @weakify(self);
- [YOUPAILCIMTool sendMessage:imMessage sessionid:session.sessionId completion:^(NIMMessage *resultMsg,NSInteger filter,NSString *contentStr) {
- @strongify(self);
- if (filter==0) {
- [[[NIMSDK sharedSDK] chatManager] sendMessage:resultMsg toSession:session error:nil];
- }else{
- resultMsg.text = contentStr;
- [[[NIMSDK sharedSDK] chatManager] sendMessage:resultMsg toSession:session error:nil];
- }
- [self.navigationController popViewControllerAnimated:YES];
- }];
- }
- - (void)youpaiploadData{
- @weakify(self);
- [LCHttpHelper requestWithURLString:GetCommonWord parameters:@{} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
- @strongify(self);
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code==0) {//成功
- self.youpaipdataSource = [YOUPAILZIMCommonWordModel mj_objectArrayWithKeyValuesArray:[dict objectForKey:@"data"]];
- [self.youpaiptableView reloadData];
- }
- } failure:^(NSError *error) {
-
- }];
- }
- @end
|