WFCUGroupMemberTableViewController.m 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. //
  2. // GroupMemberTableViewController.m
  3. // WFChat UIKit
  4. //
  5. // Created by WF Chat on 2017/9/18.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCUGroupMemberTableViewController.h"
  9. #import <WFChatClient/WFCChatClient.h>
  10. #import "WFCUGroupMemberTableViewCell.h"
  11. @interface WFCUGroupMemberTableViewController ()
  12. @property (nonatomic, strong)NSMutableArray *members;
  13. @property (nonatomic, strong)NSMutableArray *selectedMembers;;
  14. @end
  15. @implementation WFCUGroupMemberTableViewController
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. self.members = [[NSMutableArray alloc] init];
  19. self.selectedMembers = [[NSMutableArray alloc] init];
  20. self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:WFCString(@"Cancel") style:UIBarButtonItemStyleDone target:self action:@selector(onCancel:)];
  21. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:WFCString(@"Ok") style:UIBarButtonItemStyleDone target:self action:@selector(onDone:)];
  22. self.members = [[[WFCCIMService sharedWFCIMService] getGroupMembers:self.groupId forceUpdate:YES] mutableCopy];
  23. self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  24. }
  25. - (void)onCancel:(id)sender {
  26. [self dismissViewControllerAnimated:YES completion:nil];
  27. }
  28. - (void)onDone:(id)sender {
  29. if (self.selectResult) {
  30. self.selectResult(self.groupId, self.selectedMembers);
  31. }
  32. [self dismissViewControllerAnimated:YES completion:nil];
  33. }
  34. - (void)didReceiveMemoryWarning {
  35. [super didReceiveMemoryWarning];
  36. // Dispose of any resources that can be recreated.
  37. }
  38. #pragma mark - Table view data source
  39. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  40. return self.members.count;
  41. }
  42. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  43. WFCUGroupMemberTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"memberSelect"];
  44. if (cell == nil) {
  45. cell = [[WFCUGroupMemberTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"memberSelect"];
  46. if (self.selectable) {
  47. cell.isSelectable = YES;
  48. }
  49. }
  50. WFCCGroupMember *member = self.members[indexPath.row];
  51. WFCCUserInfo *user = [[WFCCIMService sharedWFCIMService] getUserInfo:member.memberId inGroup:self.groupId refresh:NO];
  52. cell.groupNameView.text = user.displayName;
  53. if (self.selectable) {
  54. if ([self.selectedMembers containsObject:member]) {
  55. cell.isSelected = YES;
  56. } else {
  57. cell.isSelected = NO;
  58. }
  59. }
  60. return cell;
  61. }
  62. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  63. return 64;
  64. }
  65. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  66. NSString *member = self.members[indexPath.row];
  67. if ([self.selectedMembers containsObject:member]) {
  68. [self.selectedMembers removeObject:member];
  69. } else {
  70. if (self.multiSelect) {
  71. [self.selectedMembers removeAllObjects];
  72. }
  73. [self.selectedMembers addObject:member];
  74. }
  75. [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
  76. }
  77. /*
  78. // Override to support conditional editing of the table view.
  79. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
  80. // Return NO if you do not want the specified item to be editable.
  81. return YES;
  82. }
  83. */
  84. /*
  85. // Override to support editing the table view.
  86. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  87. if (editingStyle == UITableViewCellEditingStyleDelete) {
  88. // Delete the row from the data source
  89. [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
  90. } else if (editingStyle == UITableViewCellEditingStyleInsert) {
  91. // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
  92. }
  93. }
  94. */
  95. /*
  96. // Override to support rearranging the table view.
  97. - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
  98. }
  99. */
  100. /*
  101. // Override to support conditional rearranging of the table view.
  102. - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
  103. // Return NO if you do not want the item to be re-orderable.
  104. return YES;
  105. }
  106. */
  107. /*
  108. #pragma mark - Navigation
  109. // In a storyboard-based application, you will often want to do a little preparation before navigation
  110. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  111. // Get the new view controller using [segue destinationViewController].
  112. // Pass the selected object to the new view controller.
  113. }
  114. */
  115. @end