SKChatListViewController.m 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // SKChatListViewController.m
  3. // Artimenring
  4. //
  5. // Created by 振兴 刘 on 16/4/12.
  6. // Copyright © 2016年 BaH Cy. All rights reserved.
  7. //
  8. #import "SKChatListViewController.h"
  9. #import "SKChatListViewCell.h"
  10. #import "DataManager.h"
  11. #import "SKChatConstants.h"
  12. #import "SKChatViewController.h"
  13. #import <UMMobClick/MobClick.h>
  14. @interface SKChatListViewController ()<UITableViewDataSource>
  15. @property(nonatomic, strong) IBOutlet UITableView *mTableView;
  16. @end
  17. @implementation SKChatListViewController
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. // Do any additional setup after loading the view.
  21. self.title = NSLocalizedString(@"SKChat.Title.List", nil);
  22. [self.navigationController setNavigationBarHidden:NO];
  23. [self addMoreButtons];
  24. }
  25. - (void)viewWillAppear:(BOOL)animated {
  26. [super viewWillAppear:animated];
  27. [self.navigationController setNavigationBarHidden:NO];
  28. [self requestSession];
  29. }
  30. - (void)onApplicationEnterForeground {
  31. [self requestSession];
  32. }
  33. - (void)onReceiveNewChat {
  34. if (self.isViewLoaded && self.view.window != nil) {
  35. [self requestSession];
  36. }
  37. }
  38. - (void)requestSession {
  39. [[DataManager shared] requestSession:^(BOOL isOK) {
  40. if (isOK) {
  41. [self.mTableView reloadData];
  42. }
  43. }];
  44. }
  45. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  46. return 1;
  47. }
  48. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  49. BOOL isEmpty = [DataManager shared].mSessionList.count <= 0;
  50. [self.view isEmptyView:isEmpty emptyImageName:@"nodata_friends"];
  51. return [DataManager shared].mSessionList.count;
  52. }
  53. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  54. return 78;
  55. }
  56. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  57. static NSString *cellID = @"SKChatListViewCellID";
  58. SKChatListViewCell *cell = (SKChatListViewCell*)[tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
  59. if(cell == nil) {
  60. cell = [[SKChatListViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellID];
  61. }
  62. SessionModel* model = [[DataManager shared].mSessionList objectAtIndex:indexPath.row];
  63. [cell setData:model];
  64. return cell;
  65. }
  66. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  67. [self.mTableView deselectRowAtIndexPath:indexPath animated:YES];
  68. [MobClick event:@"ClickChatListGotoChat"];
  69. //点击当前行后,当前行未读为0,故显示剩余行,剩余个数//
  70. [[DataManager shared] refreshUnreadCount:indexPath.row];
  71. SessionModel* model = [[DataManager shared].mSessionList objectAtIndex:indexPath.row];
  72. SKChatViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"SKChatVC"];
  73. controller.mSessionModel = model;
  74. [self pushViewController:controller animated:YES];
  75. }
  76. @end