JXChatLogVC.m 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. //
  2. // JXChatLogVC.m
  3. // shiku_im
  4. //
  5. // Created by p on 2018/7/5.
  6. // Copyright © 2018年 Reese. All rights reserved.
  7. //
  8. #import "JXChatLogVC.h"
  9. #import "JXBaseChatCell.h"
  10. #import "JXMessageCell.h"
  11. #import "JXImageCell.h"
  12. #import "JXLocationCell.h"
  13. #import "JXGifCell.h"
  14. #import "JXVideoCell.h"
  15. #import "JXEmojiCell.h"
  16. #import "JXFaceCustomCell.h"
  17. @interface JXChatLogVC ()
  18. @end
  19. @implementation JXChatLogVC
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. // Do any additional setup after loading the view.
  23. self.view.backgroundColor = HEXCOLOR(0xF2F2F2);
  24. self.tableView.backgroundColor = HEXCOLOR(0xF2F2F2);
  25. self.isShowFooterPull = NO;
  26. self.isShowHeaderPull = NO;
  27. self.isGotoBack = YES;
  28. self.heightHeader = JX_SCREEN_TOP;
  29. self.heightFooter = 0;
  30. //self.view.frame = CGRectMake(0, 0, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT);
  31. [self createHeadAndFoot];
  32. [self.tableView reloadData];
  33. }
  34. - (void)actionQuit {
  35. [super actionQuit];
  36. }
  37. #pragma mark ---------tableView协议----------------
  38. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  39. {
  40. return 1;
  41. }
  42. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  43. {
  44. return _array.count;
  45. }
  46. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  47. {
  48. JXMessageObject *msg=[_array objectAtIndex:indexPath.row];
  49. NSLog(@"indexPath.row:%ld,%ld",indexPath.section,indexPath.row);
  50. //返回对应的Cell
  51. JXBaseChatCell * cell = [self getCell:msg indexPath:indexPath];
  52. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  53. msg.changeMySend = 1;
  54. cell.msg = msg;
  55. cell.indexNum = (int)indexPath.row;
  56. cell.delegate = self;
  57. // cell.chatCellDelegate = self;
  58. // cell.readDele = @selector(readDeleWithUser:);
  59. cell.isShowHead = YES;
  60. [cell setCellData];
  61. [cell setHeaderImage];
  62. [cell setBackgroundImage];
  63. [cell isShowSendTime];
  64. //转圈等待
  65. if ([msg.isSend intValue] == transfer_status_ing) {
  66. [cell drawIsSend];
  67. }
  68. msg = nil;
  69. return cell;
  70. }
  71. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  72. }
  73. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  74. {
  75. JXMessageObject *msg=[_array objectAtIndex:indexPath.row];
  76. switch ([msg.type intValue]) {
  77. case kWCMessageTypeText:
  78. return [JXMessageCell getChatCellHeight:msg];
  79. break;
  80. case kWCMessageTypeImage:
  81. return [JXImageCell getChatCellHeight:msg];
  82. break;
  83. case kWCMessageTypeCustomFace:
  84. return [JXFaceCustomCell getChatCellHeight:msg];
  85. break;
  86. case kWCMessageTypeEmoji:
  87. return [JXEmojiCell getChatCellHeight:msg];
  88. break;
  89. case kWCMessageTypeLocation:
  90. return [JXLocationCell getChatCellHeight:msg];
  91. break;
  92. case kWCMessageTypeGif:
  93. return [JXGifCell getChatCellHeight:msg];
  94. break;
  95. case kWCMessageTypeVideo:
  96. return [JXVideoCell getChatCellHeight:msg];
  97. break;
  98. default:
  99. return [JXBaseChatCell getChatCellHeight:msg];
  100. break;
  101. }
  102. }
  103. #pragma mark -----------------获取对应的Cell-----------------
  104. - (JXBaseChatCell *)getCell:(JXMessageObject *)msg indexPath:(NSIndexPath *)indexPath{
  105. JXBaseChatCell * cell = nil;
  106. switch ([msg.type intValue]) {
  107. case kWCMessageTypeText:
  108. cell = [self creatMessageCell:msg indexPath:indexPath];
  109. break;
  110. case kWCMessageTypeImage:
  111. cell = [self creatImageCell:msg indexPath:indexPath];
  112. break;
  113. case kWCMessageTypeCustomFace:
  114. cell = [self creatFaceCustomCell:msg indexPath:indexPath];
  115. break;
  116. case kWCMessageTypeEmoji:
  117. cell = [self creatEmojiCell:msg indexPath:indexPath];
  118. break;
  119. case kWCMessageTypeLocation:
  120. cell = [self creatLocationCell:msg indexPath:indexPath];
  121. break;
  122. case kWCMessageTypeGif:
  123. cell = [self creatGifCell:msg indexPath:indexPath];
  124. break;
  125. case kWCMessageTypeVideo:
  126. cell = [self creatVideoCell:msg indexPath:indexPath];
  127. break;
  128. default:
  129. cell = [[JXBaseChatCell alloc] init];
  130. break;
  131. }
  132. return cell;
  133. }
  134. #pragma mark -----------------------创建对应的Cell---------------------
  135. //文本
  136. - (JXBaseChatCell *)creatMessageCell:(JXMessageObject *)msg indexPath:(NSIndexPath *)indexPath{
  137. NSString * identifier = @"JXMessageCell";
  138. JXMessageCell *cell=[_table dequeueReusableCellWithIdentifier:identifier];
  139. if (!cell) {
  140. cell = [[JXMessageCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
  141. }
  142. return cell;
  143. }
  144. //图片
  145. - (JXBaseChatCell *)creatImageCell:(JXMessageObject *)msg indexPath:(NSIndexPath *)indexPath{
  146. NSString * identifier = @"JXImageCell";
  147. JXImageCell *cell=[_table dequeueReusableCellWithIdentifier:identifier];
  148. if (!cell) {
  149. cell = [[JXImageCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
  150. // cell.chatImage.delegate = self;
  151. // cell.chatImage.didTouch = @selector(onCellImage:);
  152. }
  153. return cell;
  154. }
  155. // 自定义表情
  156. - (JXBaseChatCell *)creatFaceCustomCell:(JXMessageObject *)msg indexPath:(NSIndexPath *)indexPath{
  157. NSString * identifier = @"JXFaceCustomCell";
  158. JXFaceCustomCell *cell=[_table dequeueReusableCellWithIdentifier:identifier];
  159. if (!cell) {
  160. cell = [[JXFaceCustomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
  161. // cell.chatImage.delegate = self;
  162. // cell.chatImage.didTouch = @selector(onCellImage:);
  163. }
  164. return cell;
  165. }
  166. // 表情包
  167. - (JXBaseChatCell *)creatEmojiCell:(JXMessageObject *)msg indexPath:(NSIndexPath *)indexPath{
  168. NSString * identifier = @"JXEmojiCell";
  169. JXEmojiCell *cell=[_table dequeueReusableCellWithIdentifier:identifier];
  170. if (!cell) {
  171. cell = [[JXEmojiCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
  172. // cell.chatImage.delegate = self;
  173. // cell.chatImage.didTouch = @selector(onCellImage:);
  174. }
  175. return cell;
  176. }
  177. //视频
  178. - (JXBaseChatCell *)creatVideoCell:(JXMessageObject *)msg indexPath:(NSIndexPath *)indexPath{
  179. NSString * identifier = @"JXVideoCell";
  180. JXVideoCell *cell=[_table dequeueReusableCellWithIdentifier:identifier];
  181. if (!cell) {
  182. cell = [[JXVideoCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
  183. }
  184. return cell;
  185. }
  186. //位置
  187. - (JXBaseChatCell *)creatLocationCell:(JXMessageObject *)msg indexPath:(NSIndexPath *)indexPath{
  188. NSString * identifier = @"JXLocationCell";
  189. JXLocationCell *cell=[_table dequeueReusableCellWithIdentifier:identifier];
  190. if (!cell) {
  191. cell = [[JXLocationCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
  192. }
  193. return cell;
  194. }
  195. //动画
  196. - (JXBaseChatCell *)creatGifCell:(JXMessageObject *)msg indexPath:(NSIndexPath *)indexPath{
  197. NSString * identifier = @"JXGifCell";
  198. JXGifCell *cell=[_table dequeueReusableCellWithIdentifier:identifier];
  199. if (!cell) {
  200. cell = [[JXGifCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
  201. }
  202. return cell;
  203. }
  204. - (void)didReceiveMemoryWarning {
  205. [super didReceiveMemoryWarning];
  206. // Dispose of any resources that can be recreated.
  207. }
  208. /*
  209. #pragma mark - Navigation
  210. // In a storyboard-based application, you will often want to do a little preparation before navigation
  211. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  212. // Get the new view controller using [segue destinationViewController].
  213. // Pass the selected object to the new view controller.
  214. }
  215. */
  216. @end