// // DetailViewController.m // iShop // // Created by Rui Zhang on 12/15/23. // #import "CatalogModelDetailViewController.h" #import "RANetwork.h" #import "RAUtils.h" #import "DetailSlideImageCell.h" #import "SliderPage.h" #import "RTLabel.h" #import "DetailKVCell.h" #import "LineView.h" #import "DetailBasicCell0.h" #import "FileCache.h" #import "ColorSelectViewController.h" #import "CustomPresentationController.h" #define RTLABEL_FONT_SIZE 15 #define DEF_CELL_HEIGHT 44 #define DEF_TABLE_HEIGHT 44 #define LINE_WIDTH 10 #define CELL_MARGIN 0 #define LABEL_MARGIN 10 @interface CatalogModelDetailViewController () @end @implementation CatalogModelDetailViewController - (void)viewDidLoad { [super viewDidLoad]; self.show_navi = true; // Do any additional setup after loading the view. } //- (void)setDetail_data:(NSMutableDictionary *)detail_data //{ // NSMutableDictionary* data = [NSMutableDictionary new]; // // // NSMutableDictionary* img_section=detail_data[@"img_section"]; //// NSMutableDictionary* img=detail_data[@"images"]; //// NSMutableDictionary* video=detail_data[@"videos"]; //// //// NSMutableDictionary* new_res =[NSMutableDictionary new]; //// int new_count = 0; //// for(int i=0;i1) // return true; // else // return false; //} //- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath //{ // NSMutableArray * from; // NSMutableArray * to ; // if(fromIndexPath.section==0) // from = self.displayfields; // else // from = self.hidefields; // if(toIndexPath.section==0) // to = self.displayfields; // else // to = self.hidefields; // id content=from[fromIndexPath.row]; // [from removeObjectAtIndex:fromIndexPath.row]; // [to insertObject:content atIndex:toIndexPath.row]; // // [tableView reloadData]; // //} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if(section==0) return 2; NSDictionary* related_json = [self.detail_data objectForKey:@"related_model"]; if(related_json==nil) { NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)section-1]]; NSString* type=[section_json valueForKey:@"type"] ; if([type isEqualToString:@"content"]) return 1; return [[section_json valueForKey:@"count"] intValue]; } else { if(section==1) return 1; else { NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)section-2]]; NSString* type=[section_json valueForKey:@"type"] ; if([type isEqualToString:@"content"]) return 1; return [[section_json valueForKey:@"count"] intValue]; } } } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { if(section ==0) return 0; else return 33; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath; { if(indexPath.section ==0) return 295; else if(indexPath.section==2||indexPath.section==3) return 270; NSDictionary* nsdic = self.detail_data; NSDictionary* related_json = [self.detail_data objectForKey:@"related_model"]; if(related_json==nil) { NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)indexPath.section-1]]; NSDictionary* item_json =[section_json objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row ]]; NSString* type=[section_json valueForKey:@"type"] ; if([type isEqualToString:@"kv"]) { float width = tableView.frame.size.width; width-=CELL_MARGIN*2; CGSize constraintkey = CGSizeMake(width*0.4-2*LABEL_MARGIN, 20000.0f);//key label width is 40% cell width; CGSize constraintval = CGSizeMake(width*0.6-2*LABEL_MARGIN, 20000.0f);//val label width is 60% cell width; // NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row]; NSString* key =[item_json valueForKey:@"key"] ; // [cell.keyLabel sizeToFit]; NSString* val=[item_json valueForKey:@"val"] ; if([val isEqual:[NSNull null]]) val=@""; if(val==nil) val=@""; if([val isEqualToString:@"null"]) val=@""; CGRect frame; frame.size = constraintval; frame.origin.x=0; frame.origin.y=0; RTLabel* rtlabel = [[RTLabel alloc] initWithFrame:frame]; [rtlabel setLineBreakMode: RTTextLineBreakModeWordWrapping]; // rtlabel.lineSpacing = 20.0; [rtlabel setText: val]; rtlabel.font = [UIFont systemFontOfSize:RTLABEL_FONT_SIZE]; CGSize sizeval=rtlabel.optimumSize; // // // CGSize sizeval0=[RAUtils sizeWithFont:val font:[UIFont systemFontOfSize:RTLABEL_FONT_SIZE] constrainedToSize:constraintval lineBreakMode:NSLineBreakByWordWrapping]; // // // CGSize sizekey = [key sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping]; // CGSize sizekey = [RAUtils sizeWithFont:key font:[UIFont systemFontOfSize:RTLABEL_FONT_SIZE] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping]; frame.size =constraintkey; UILabel* label = [[UILabel alloc] initWithFrame:frame]; [label setLineBreakMode:NSLineBreakByWordWrapping]; label.font=[UIFont systemFontOfSize:RTLABEL_FONT_SIZE]; label.text = key; CGSize sizekey =[label sizeThatFits:label.frame.size]; // rtlabel.text = key; // CGSize sizekey =rtlabel.optimumSize; // CGSize sizeval = [val sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintval lineBreakMode:NSLineBreakByWordWrapping]; float height = MAX(sizekey.height,sizeval.height); height = MAX(height+LINE_WIDTH, DEF_CELL_HEIGHT); return height; } else if([type isEqualToString:@"img"]) { int img_count = [[item_json valueForKey:@"count"] intValue]; double ret = 0; for(int j=0;j 4) { // height = 70 * 4.5; // } // self.dropDown =[[NIDropDown alloc] showDropDown:trigger.superview based:(id)trigger height:height data:self.selector direction:@"up" current_sel:current_sel]; // // // //Capturing strongly warring; // __block CatalogModelDetailViewController *brself= self; // self.dropDown.dropDownTouchOutsideBlk = ^{ // [brself.dropDown hideDropDown:(id)trigger]; // brself.dropDown= nil; // }; // // // } // else { // [self.dropDown hideDropDown:(id)trigger]; // self.dropDown= nil; // } return; } #pragma mark - Topic cell delegate -(void) TopicItemClicked:(NSString*) product_id category:(NSString*) category { if(true) { CatalogModelDetailViewController* dvc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"CatalogModelDetailViewController" ]; // dvc.OnBack=^(bool add_cart,bool add_wish,bool update_data) // { // // // NSMutableDictionary* items =[[self.category_data objectForKey:@"items"] mutableCopy]; // // NSMutableDictionary* item = [[items objectForKey:[NSString stringWithFormat:@"item_%ld",index]] mutableCopy]; // if(add_cart) // item[@"cart_exists"]=@"true"; // if(add_wish) // item[@"wish_exists"]=@"true"; // items[[NSString stringWithFormat:@"item_%ld",index]] = item; // self.category_data[@"items"]=items; // // [self.collectionview reloadData]; // }; dvc.product_id = product_id; dvc.category_id=category; dvc.ispush = true; // dvc.model_name = name; [dvc reload]; [self.navigationController pushViewController:dvc animated:true]; return; } else { // self.model_name = value; self.product_id = product_id; self.category_id=category; [self reload]; DebugLog(@"color selected"); } } @end