QMPickedOtherViewController.m 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. //
  2. // QMPickedOtherViewController.m
  3. // IMSDK-OC
  4. //
  5. // Created by HCF on 16/8/10.
  6. // Copyright © 2016年 HCF. All rights reserved.
  7. //
  8. #import "QMPickedOtherViewController.h"
  9. #import "QMFileManager.h"
  10. #import "QMFileTabbarView.h"
  11. #import "QMProfileManager.h"
  12. #import "QMFileTableCell.h"
  13. #import "QMFileModel.h"
  14. #import "QMChatRoomViewController.h"
  15. @interface QMPickedOtherViewController ()<UITableViewDelegate, UITableViewDataSource> {
  16. UITableView *_tableView;
  17. QMFileTabbarView *_tabbarView;
  18. NSArray *_otherArray;
  19. CGFloat _navHeight;
  20. }
  21. @property (nonatomic, strong) NSMutableSet *pickedOtherSet;
  22. @end
  23. @implementation QMPickedOtherViewController
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. CGRect StatusRect = [[UIApplication sharedApplication] statusBarFrame];
  27. CGRect NavRect = self.navigationController.navigationBar.frame;
  28. _navHeight = StatusRect.size.height + NavRect.size.height;
  29. self.view.backgroundColor = [UIColor whiteColor];
  30. self.pickedOtherSet = [[NSMutableSet alloc] initWithCapacity:10];
  31. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight-_navHeight-44) style:UITableViewStylePlain];
  32. _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
  33. _tableView.backgroundColor = [UIColor whiteColor];
  34. _tableView.delegate = self;
  35. _tableView.dataSource = self;
  36. [self.view addSubview:_tableView];
  37. _tabbarView = [[QMFileTabbarView alloc] init];
  38. _tabbarView.frame = CGRectMake(0, kScreenHeight-44-_navHeight, kScreenWidth, 44);
  39. [self.view addSubview:_tabbarView];
  40. [_tableView registerClass:[QMFileTableCell class] forCellReuseIdentifier:NSStringFromClass(QMFileTableCell.self)];
  41. __weak QMPickedOtherViewController *strongSelf = self;
  42. _tabbarView.selectAction = ^{
  43. QMChatRoomViewController * tagViewController = nil;
  44. for (UIViewController *viewController in strongSelf.navigationController.viewControllers) {
  45. if ([viewController isKindOfClass:[QMChatRoomViewController class]]) {
  46. tagViewController = (QMChatRoomViewController *)viewController;
  47. [strongSelf.navigationController popToViewController:tagViewController animated:true];
  48. for (QMFileModel *model in strongSelf.pickedOtherSet) {
  49. [tagViewController sendFileMessageWithName:model.fileName AndSize:model.fileSize AndPath:model.fileName];
  50. }
  51. }
  52. }
  53. };
  54. [self getData];
  55. }
  56. - (void)dealloc {
  57. }
  58. - (void)getData {
  59. QMProfileManager * manager = [QMProfileManager sharedInstance];
  60. _otherArray = [manager getFilesAttributes:OTHER];
  61. [_tableView reloadData];
  62. }
  63. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  64. return 80;
  65. }
  66. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  67. return 0.1;
  68. }
  69. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  70. return 0.1;
  71. }
  72. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  73. return _otherArray.count;
  74. }
  75. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  76. QMFileTableCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(QMFileTableCell.self) forIndexPath:indexPath];
  77. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  78. return cell;
  79. }
  80. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  81. QMFileModel *model = _otherArray[indexPath.row];
  82. if ([cell isKindOfClass:[QMFileTableCell class]]) {
  83. QMFileTableCell *displayCell = (QMFileTableCell *)cell;
  84. [displayCell configureWithModel:model];
  85. displayCell.pickedItemImageView.hidden = ![self.pickedOtherSet containsObject:model];
  86. }
  87. }
  88. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  89. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  90. QMFileModel *model = _otherArray[indexPath.row];
  91. if ([self.pickedOtherSet containsObject:model]) {
  92. [self.pickedOtherSet removeObject:model];
  93. }else {
  94. if ([self.pickedOtherSet count]>0) {
  95. }else {
  96. [self.pickedOtherSet addObject:model];
  97. }
  98. }
  99. QMFileTableCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  100. cell.pickedItemImageView.hidden = ![self.pickedOtherSet containsObject:model];
  101. if ([self.pickedOtherSet count]>0) {
  102. _tabbarView.doneButton.selected = YES;
  103. }else {
  104. _tabbarView.doneButton.selected = NO;
  105. }
  106. }
  107. - (void)didReceiveMemoryWarning {
  108. [super didReceiveMemoryWarning];
  109. // Dispose of any resources that can be recreated.
  110. }
  111. @end