JXSelectFriendVC.m 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. //
  2. // JXSelectFriendVC.m
  3. // share
  4. //
  5. // Created by 1 on 2019/3/20.
  6. // Copyright © 2019年 Reese. All rights reserved.
  7. //
  8. #import "JXSelectFriendVC.h"
  9. #import "JXShareUser.h"
  10. #import "JXFriendCell.h"
  11. // 多端登录userId
  12. #define PC_USERID [NSString stringWithFormat:@"%@_pc",g_myself.userId]
  13. #define ANDROID_USERID [NSString stringWithFormat:@"%@_android",g_myself.userId]
  14. #define MAC_USERID [NSString stringWithFormat:@"%@_mac",g_myself.userId]
  15. #define WEB_USERID [NSString stringWithFormat:@"%@_web",g_myself.userId]
  16. #define IOS_USERID [NSString stringWithFormat:@"%@_ios",g_myself.userId]
  17. #define SQUARE_HEIGHT 38 //图片宽高
  18. @interface JXSelectFriendVC () <UITextFieldDelegate,UIScrollViewDelegate,UITableViewDelegate,UITableViewDataSource>
  19. @property (nonatomic, strong) UITextField *seekTextField;
  20. @property (nonatomic, strong) UITableView *tableView;
  21. @property (nonatomic, strong) JXShareUser *user;
  22. @property (nonatomic, strong) NSArray *data;
  23. @end
  24. @implementation JXSelectFriendVC
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. [self getData];
  28. UIView *baseView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT)];
  29. baseView.backgroundColor = [UIColor whiteColor];
  30. [self.view addSubview:baseView];
  31. UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, JX_SCREEN_TOP)];
  32. [baseView addSubview:headView];
  33. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(8, JX_SCREEN_TOP - 40, 31, 31)];
  34. [btn setImage:[UIImage imageNamed:@"share_back"] forState:UIControlStateNormal];
  35. [btn addTarget:self action:@selector(actionQuit) forControlEvents:UIControlEventTouchUpInside];
  36. [headView addSubview:btn];
  37. UILabel* p = [[UILabel alloc]initWithFrame:CGRectMake(60, JX_SCREEN_TOP - 35, JX_SCREEN_WIDTH-60*2, 20)];
  38. p.backgroundColor = [UIColor clearColor];
  39. p.textAlignment = NSTextAlignmentCenter;
  40. p.text = @"发送给朋友";
  41. p.font = [UIFont boldSystemFontOfSize:18.0];
  42. [headView addSubview:p];
  43. UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, JX_SCREEN_TOP-LINE_WH, JX_SCREEN_WIDTH, LINE_WH)];
  44. line.backgroundColor = [UIColor lightGrayColor];
  45. [headView addSubview:line];
  46. self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, JX_SCREEN_TOP, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT-JX_SCREEN_TOP)];
  47. self.tableView.delegate = self;
  48. self.tableView.dataSource = self;
  49. [baseView addSubview:self.tableView];
  50. [self customSearchTextField];
  51. }
  52. - (void)getData {
  53. self.data = [[JXShareUser shareInstance] getAllUser];
  54. }
  55. - (void)customSearchTextField{
  56. //搜索输入框
  57. UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, JX_SCREEN_TOP, JX_SCREEN_WIDTH, 55)];
  58. [self.view addSubview:backView];
  59. _seekTextField = [[UITextField alloc] initWithFrame:CGRectMake(15, 10, backView.frame.size.width - 30, 35)];
  60. _seekTextField.placeholder = @"搜索";
  61. _seekTextField.textColor = [UIColor blackColor];
  62. [_seekTextField setFont:SYSFONT(14)];
  63. _seekTextField.backgroundColor = HEXCOLOR(0xf0f0f0);
  64. UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"card_search"]];
  65. UIView *leftView = [[UIView alloc ]initWithFrame:CGRectMake(0, 0, 30, 30)];
  66. imageView.center = leftView.center;
  67. [leftView addSubview:imageView];
  68. _seekTextField.leftView = leftView;
  69. _seekTextField.leftViewMode = UITextFieldViewModeAlways;
  70. _seekTextField.borderStyle = UITextBorderStyleNone;
  71. _seekTextField.layer.masksToBounds = YES;
  72. _seekTextField.layer.cornerRadius = 3.f;
  73. _seekTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
  74. _seekTextField.delegate = self;
  75. _seekTextField.returnKeyType = UIReturnKeyGoogle;
  76. [backView addSubview:_seekTextField];
  77. [_seekTextField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  78. self.tableView.tableHeaderView = backView;
  79. }
  80. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  81. if ([_seekTextField isFirstResponder]) {
  82. [_seekTextField resignFirstResponder];
  83. }
  84. }
  85. - (void)textFieldDidChange:(UITextField *)textField {
  86. self.data = [[JXShareUser shareInstance] fetchSearchUserWithString:textField.text];
  87. [self.tableView reloadData];
  88. }
  89. #pragma mark - Table view data source
  90. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  91. return 1;
  92. }
  93. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  94. return self.data.count;
  95. }
  96. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  97. return 64;
  98. }
  99. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  100. static NSString *cellIdentifier = @"JXFriendCell";
  101. JXFriendCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
  102. if (!cell) {
  103. cell = [[JXFriendCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
  104. }
  105. JXShareUser *user = self.data[indexPath.row];
  106. [cell setDataWithUser:user];
  107. return cell;
  108. }
  109. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  110. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  111. JXShareUser *user = self.data[indexPath.row];
  112. if (self.delegate && [self.delegate respondsToSelector:@selector(sendToFriendSuccess:user:)]) {
  113. [self.delegate sendToFriendSuccess:self user:user];
  114. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  115. [self actionQuit];
  116. });
  117. }
  118. }
  119. - (void)actionQuit {
  120. [self dismissViewControllerAnimated:NO completion:nil];
  121. }
  122. @end