CatalogViewController.m 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. //
  2. // CatalogViewController.m
  3. // iShop
  4. //
  5. // Created by Rui Zhang on 12/14/23.
  6. //
  7. #import "CatalogViewController.h"
  8. #import "RANetwork.h"
  9. #import "CatalogListViewController.h"
  10. @interface CatalogViewController ()
  11. @end
  12. @implementation CatalogViewController
  13. - (void)viewDidLoad {
  14. [super viewDidLoad];
  15. // Do any additional setup after loading the view.
  16. self.strtitle=@"";
  17. self.show_navi = true;
  18. if(self.categoryMenu==nil)
  19. {
  20. if(RASingleton.sharedInstance.categoryMenu)
  21. {
  22. self.categoryMenu = RASingleton.sharedInstance.categoryMenu;
  23. [self.tableView reloadData];
  24. self.strtitle= @"Shop by Department";
  25. }
  26. else
  27. {
  28. [RANetwork request_category:^(NSMutableDictionary *result) {
  29. NSDictionary* category=result;
  30. if([[category valueForKey:@"result"] intValue]==2)
  31. {
  32. self.categoryMenu = category;
  33. [self.tableView reloadData];
  34. self.strtitle= @"Shop by Department";
  35. }
  36. }];
  37. }
  38. return;
  39. }
  40. else
  41. {
  42. self.strtitle = self.categoryMenu[@"title"];
  43. self.title = self.categoryMenu[@"title"];
  44. }
  45. }
  46. - (void)viewWillAppear:(BOOL)animated
  47. {
  48. [super viewWillAppear:animated];
  49. }
  50. #pragma mark tableview
  51. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  52. //{
  53. // return 20;
  54. //}
  55. //- (nullable NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
  56. //{
  57. //
  58. //
  59. //
  60. //// return @"abc";
  61. //
  62. // if(self.strtitle.length>0)
  63. // {
  64. // return self.strtitle;
  65. // }
  66. // else
  67. // return @" ";
  68. //}
  69. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  70. return [self.categoryMenu[@"count"] intValue];
  71. }
  72. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  73. static NSString *CellIdentifier = @"Cell";
  74. // UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  75. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  76. if (!cell) {
  77. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  78. }
  79. NSString* key = [NSString stringWithFormat:@"category_%ld", indexPath.row];
  80. cell.textLabel.text =self.categoryMenu[key][@"title"];
  81. int child_count =[self.categoryMenu[key][@"count"] intValue];
  82. if(child_count>0)
  83. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  84. return cell;
  85. }
  86. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath
  87. {
  88. NSString* key = [NSString stringWithFormat:@"category_%ld", indexPath.row];
  89. int child_count =[self.categoryMenu[key][@"count"] intValue];
  90. if(child_count>0)
  91. {
  92. CatalogViewController* vc = [[UIStoryboard storyboardWithName:@"Frame" bundle:nil] instantiateViewControllerWithIdentifier:@"CatalogViewController"];
  93. vc.show_navi = true;
  94. vc.categoryMenu =self.categoryMenu[key];
  95. [self.navigationController pushViewController:vc animated:TRUE];
  96. }
  97. else{
  98. CatalogListViewController* vc= [[UIStoryboard storyboardWithName:@"catalog" bundle:nil] instantiateViewControllerWithIdentifier:@"CatalogListViewController"];
  99. vc.categoryid = self.categoryMenu[key][@"id"];
  100. [self.navigationController pushViewController:vc animated:TRUE];
  101. }
  102. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  103. // CBPeripheral *p=appDelegate.nDevices[indexPath.item];
  104. //
  105. //
  106. // // 如果点到当前连接设备,则忽略。
  107. // if([appDelegate.peripheral.identifier.UUIDString isEqualToString:p.identifier.UUIDString])
  108. // return;
  109. // [self onDisconnect:nil];
  110. //// self.needVerifyUUID=p.identifier.UUIDString;
  111. // appDelegate.peripheral = p;
  112. // [appDelegate.manager connectPeripheral:appDelegate.peripheral options:nil];
  113. }
  114. /*
  115. #pragma mark - Navigation
  116. // In a storyboard-based application, you will often want to do a little preparation before navigation
  117. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  118. // Get the new view controller using [segue destinationViewController].
  119. // Pass the selected object to the new view controller.
  120. }
  121. */
  122. @end