SearchResultView.m 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. //
  2. // SearchResultView.m
  3. // YBVideo
  4. //
  5. // Created by YunBao on 2018/7/20.
  6. // Copyright © 2018年 cat. All rights reserved.
  7. //
  8. #import "SearchResultView.h"
  9. #import "LocationCell.h"
  10. @interface SearchResultView()<UITableViewDelegate,UITableViewDataSource>
  11. @end
  12. @implementation SearchResultView
  13. - (instancetype)initWithFrame:(CGRect)frame {
  14. self = [super initWithFrame:frame];
  15. if (self) {
  16. self.backgroundColor = Normal_Color;
  17. self.pageIndex = 1;
  18. [self setupTableView];
  19. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshData:) name:SearchResultGetPoiSearchResult object:nil];
  20. }
  21. return self;
  22. }
  23. - (NSMutableArray<QMSPoiData *> *)dataSource {
  24. if (!_dataSource) {
  25. _dataSource = [NSMutableArray array];
  26. }
  27. return _dataSource;
  28. }
  29. - (void)setupTableView {
  30. self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0, _window_width, self.height) style:UITableViewStylePlain];
  31. self.tableView.dataSource = self;
  32. self.tableView.delegate = self;
  33. self.tableView.tableFooterView = [[UIView alloc] init];
  34. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  35. self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
  36. self.tableView.backgroundColor = Normal_Color;
  37. [self addSubview:self.tableView];
  38. MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadPastData)];
  39. self.tableView.mj_footer = footer;
  40. [footer setTitle:@"" forState:MJRefreshStateIdle];
  41. [footer setTitle:@"" forState:MJRefreshStatePulling];
  42. [footer setTitle:YZMsg(@"正在刷新数据") forState:MJRefreshStateRefreshing];
  43. // 设置字体
  44. footer.stateLabel.font = [UIFont systemFontOfSize:14];
  45. // 设置颜色
  46. footer.stateLabel.textColor = [UIColor blackColor];
  47. }
  48. - (void)loadPastData {
  49. [self.tableView.mj_footer endRefreshing];
  50. if (self.dataSource.count == 0) {
  51. self.pageIndex = 1;
  52. } else {
  53. self.pageIndex = self.pageIndex + 1;
  54. }
  55. self.searchResultsPage(self.pageIndex);
  56. }
  57. - (void)refreshData:(NSNotification *)notification {
  58. NSArray *array = (notification.userInfo[@"data"]);
  59. if (self.pageIndex == 1) {
  60. [self.dataSource removeAllObjects];
  61. self.dataSource = [NSMutableArray arrayWithArray:array];
  62. [self.tableView setContentOffset:CGPointMake(0, 0)];
  63. }else {
  64. [self.dataSource addObjectsFromArray:array];
  65. }
  66. [self.tableView reloadData];
  67. }
  68. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  69. return self.dataSource.count;
  70. }
  71. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  72. return 60;
  73. }
  74. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  75. LocationCell *cell = [LocationCell cellWithTab:tableView andIndexPath:indexPath];
  76. cell.addressL.text = self.dataSource[indexPath.row].title;
  77. cell.infoL.text = self.dataSource[indexPath.row].address;
  78. cell.backgroundColor = CellRow_Cor;
  79. cell.falgIV.hidden = YES;
  80. cell.selectedBackgroundView = [[UIImageView alloc]initWithImage:[PublicObj getImgWithColor:SelCell_Col]];
  81. return cell;
  82. }
  83. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  84. if (self.dismissEvent) {
  85. self.dismissEvent([self.dataSource objectAtIndex:indexPath.row]);
  86. }
  87. }
  88. @end