RAHomeViewController+HomeTableDelegate.m 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. if (section == 0) {
  42. badgeNumberView.badgeNumber = 20;
  43. } else {
  44. badgeNumberView.badgeNumber = 999;
  45. }
  46. moreBtn.tag = 6000 + section;
  47. [moreBtn addTarget:self action:@selector(sectionExpandSwithBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  48. moreBtn.hidden = ![self hasMoreOrderForSection:section];
  49. return header;
  50. }
  51. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  52. return 44.f;
  53. }
  54. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  55. RAHomeOrderModel *order = [self orderModelForIndexPath:indexPath];
  56. self.currentOrderID = order.orderID;
  57. [self pushDetailViewControllerForModel:order];
  58. }
  59. #pragma mark - Action
  60. - (void)sectionExpandSwithBtnClick:(UIButton *)sender {
  61. [self showMoreOrderForSection:sender.tag - 6000];
  62. }
  63. @end