RAHomeViewController+HomeTableDelegate.m 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //
  2. // RAHomeViewController+HomeTableDelegate.m
  3. // Apex And Drivers
  4. //
  5. // Created by Jack on 2018/6/1.
  6. // Copyright © 2018年 USAI. All rights reserved.
  7. //
  8. #import "RAHomeViewController+HomeTableDelegate.h"
  9. #import "RAHomeOrderModel.h"
  10. #import "RABadgeNumberView.h"
  11. @implementation RAHomeViewController (HomeTableDelegate)
  12. #pragma mark - TableView Delegate
  13. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  14. return 140.0f;
  15. }
  16. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  17. // UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(tableView.bounds), 44.0f)];
  18. // header.backgroundColor = [UIColor colorWithRed:0.8 green:0.8 blue:0.8 alpha:0.8];
  19. // UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 11, CGRectGetWidth(tableView.bounds) - 100, 22)];
  20. // [header addSubview:label];
  21. //
  22. // label.text = [self titleForSection:section];
  23. //
  24. // UIButton *expandBtn = [UIButton buttonWithType:UIButtonTypeSystem];
  25. // expandBtn.frame = CGRectMake(CGRectGetWidth(tableView.bounds) - 90, 11, 80, 22);
  26. // [expandBtn setTitle:@"More" forState:UIControlStateNormal];
  27. //
  28. //
  29. // expandBtn.tag = section;
  30. // [expandBtn addTarget:self action:@selector(sectionExpandSwithBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  31. // [header addSubview:expandBtn];
  32. //
  33. // expandBtn.hidden = ![self hasMoreOrderForSection:section];
  34. //
  35. UIView *header = [[[NSBundle mainBundle] loadNibNamed:@"HomeHeader" owner:nil options:nil] objectAtIndex:0];
  36. header.backgroundColor = [UIColor colorWithRed:0.8 green:0.8 blue:0.8 alpha:0.8];
  37. UILabel *titleLabel = (UILabel *)[header viewWithTag:5000];
  38. RABadgeNumberView *badgeNumberView = (RABadgeNumberView *)[header viewWithTag:5001];
  39. UIButton *moreBtn = (UIButton *)[header viewWithTag:5002];
  40. titleLabel.text = [self titleForSection:section];
  41. badgeNumberView.badgeNumber = [self backendCountForSection:section];
  42. moreBtn.tag = 6000 + section;
  43. [moreBtn addTarget:self action:@selector(sectionExpandSwithBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  44. moreBtn.hidden = ![self hasMoreOrderForSection:section];
  45. return header;
  46. }
  47. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  48. return 44.f;
  49. }
  50. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  51. RAHomeOrderModel *order = [self orderModelForIndexPath:indexPath];
  52. if (order.backendFlag) {
  53. order.backendFlag = !order.backendFlag;
  54. }
  55. self.currentOrderID = order.orderID;
  56. [self pushDetailViewControllerForModel:order];
  57. }
  58. #pragma mark - Action
  59. - (void)sectionExpandSwithBtnClick:(UIButton *)sender {
  60. [self showMoreOrderForSection:sender.tag - 6000];
  61. }
  62. @end