// // CatalogViewController.m // iShop // // Created by Rui Zhang on 12/14/23. // #import "CatalogViewController.h" #import "RANetwork.h" #import "CatalogListViewController.h" @interface CatalogViewController () @end @implementation CatalogViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.strtitle=@""; self.show_navi = true; if(self.categoryMenu==nil) { if(RASingleton.sharedInstance.categoryMenu) { self.categoryMenu = RASingleton.sharedInstance.categoryMenu; [self.tableView reloadData]; self.strtitle= @"Shop by Department"; } else { [RANetwork request_category:^(NSMutableDictionary *result) { NSDictionary* category=result; if([[category valueForKey:@"result"] intValue]==2) { self.categoryMenu = category; [self.tableView reloadData]; self.strtitle= @"Shop by Department"; } }]; } return; } else { self.strtitle = self.categoryMenu[@"title"]; self.title = self.categoryMenu[@"title"]; } } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; } #pragma mark tableview //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section //{ // return 20; //} //- (nullable NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section //{ // // // //// return @"abc"; // // if(self.strtitle.length>0) // { // return self.strtitle; // } // else // return @" "; //} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [self.categoryMenu[@"count"] intValue]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; // UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } NSString* key = [NSString stringWithFormat:@"category_%ld", indexPath.row]; cell.textLabel.text =self.categoryMenu[key][@"title"]; int child_count =[self.categoryMenu[key][@"count"] intValue]; if(child_count>0) cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath { NSString* key = [NSString stringWithFormat:@"category_%ld", indexPath.row]; int child_count =[self.categoryMenu[key][@"count"] intValue]; if(child_count>0) { CatalogViewController* vc = [[UIStoryboard storyboardWithName:@"Frame" bundle:nil] instantiateViewControllerWithIdentifier:@"CatalogViewController"]; vc.show_navi = true; vc.categoryMenu =self.categoryMenu[key]; [self.navigationController pushViewController:vc animated:TRUE]; } else{ CatalogListViewController* vc= [[UIStoryboard storyboardWithName:@"catalog" bundle:nil] instantiateViewControllerWithIdentifier:@"CatalogListViewController"]; vc.categoryid = self.categoryMenu[key][@"id"]; [self.navigationController pushViewController:vc animated:TRUE]; } // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; // CBPeripheral *p=appDelegate.nDevices[indexPath.item]; // // // // 如果点到当前连接设备,则忽略。 // if([appDelegate.peripheral.identifier.UUIDString isEqualToString:p.identifier.UUIDString]) // return; // [self onDisconnect:nil]; //// self.needVerifyUUID=p.identifier.UUIDString; // appDelegate.peripheral = p; // [appDelegate.manager connectPeripheral:appDelegate.peripheral options:nil]; } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end