// // CommonEditorViewController.m // RedAnt ERP Mobile // // Created by Ray on 14-7-16. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved. // #import "CommonEditorViewController.h" #import "CommonEditorCellEdit.h" #import "RASingleton.h" //#import "RANetwork.h" #import "CommonEditorCellEnum.h" #import "CommonEditorCellEditor.h" #import "CommonEditorCellSwitch.h" #import "CommonEditorCellModel.h" #import "CommonEditorCellAction.h" #import "EnumSelectViewController.h" #import "DatePickerViewController.h" #import "SignatureViewController.h" #import "CommonEditorCellSignature.h" #import "CommonEditorCellLabel.h" //#import "AddressEditorViewController.h" //#import "CreditCardEditorViewController.h" #import "MonthPickerViewController.h" //#import "ContactListViewController.h" #import "CommonEditorCellMAction.h" #import "CommonEditorCellTextView.h" #import "RAUtils.h" #import "CommonEditorCellImg.h" #import "RAConvertor.h" //#import "AFHTTPSessionManager.h" //#import "NetworkUtils.h" #import "config.h" #import "CustomIOSAlertView.h" #import "DefaultAppearance.h" #import "DefaultTableHeaderView.h" #define INTNUMBERS @"0123456789\n" #define NUMBERS @"0123456789.\n" # ifdef OFFLINE_MODE #import "OLDataProvider.h" # endif #import //#import "MainViewController.h" #import "AppDelegate.h" #import "FileCache.h" //#import "RAConvertor.h" #import "EnumSelectAndSortViewController.h" #import "CommonEditorRangeCell.h" #import "CommonEditorWebCell.h" #import "CommonEditorBannerCell.h" #import "ContentPreviewController.h" #import "NetworkUtils.h" #import "EnumSelectOnlineViewController.h" #import "common_const.h" @interface subitem_data () @end @implementation subitem_data @end @interface CommonEditorViewController () @end @implementation CommonEditorViewController - (void)viewDidLayoutSubviews { [super viewDidLayoutSubviews]; [self resize_tableHeader]; } #pragma mark - Code TableView - (UIView*)get_tableHeader { return [UIView new]; } -(void) resize_tableHeader { //利用systemLayoutSizeFittingSize:计算出真实高度 CGFloat height = [self.editorTable.tableHeaderView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height; CGRect headerFrame = self.editorTable.tableHeaderView.frame; headerFrame.size.height = height;//20是留的上下边距 //修改tableHeaderView的frame self.editorTable.tableHeaderView.frame = headerFrame; } - (void)initTableView { self.editorTable = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain]; self.editorTable.translatesAutoresizingMaskIntoConstraints = NO; [self.tableContainer addSubview:self.editorTable]; [self.tableContainer sendSubviewToBack:self.editorTable]; NSLayoutConstraint *top_constraint = [NSLayoutConstraint constraintWithItem:self.editorTable attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.tableContainer attribute:NSLayoutAttributeTop multiplier:1 constant:0]; self.tb_top_constraint = top_constraint; [self.tableContainer addConstraint:top_constraint]; NSLayoutConstraint *left_constraint = [NSLayoutConstraint constraintWithItem:self.editorTable attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.tableContainer attribute:NSLayoutAttributeLeft multiplier:1 constant:0]; self.tb_left_constraint = left_constraint; [self.tableContainer addConstraint:left_constraint]; NSLayoutConstraint *bottom_constraint = [NSLayoutConstraint constraintWithItem:self.editorTable attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.tableContainer attribute:NSLayoutAttributeBottom multiplier:1 constant:0]; self.tb_bottom_constraint = bottom_constraint; [self.tableContainer addConstraint:bottom_constraint]; NSLayoutConstraint *right_constraint = [NSLayoutConstraint constraintWithItem:self.editorTable attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.tableContainer attribute:NSLayoutAttributeRight multiplier:1 constant:0]; self.tb_right_constraint = right_constraint; [self.tableContainer addConstraint:right_constraint]; self.editorTable.delegate = self; self.editorTable.dataSource = self; self.editorTable.tableFooterView = [UIView new]; // self.editorTable.tableHeaderView = [UIView new]; self.editorTable.tableHeaderView = [self get_tableHeader]; } - (void)registerPhoneCell { [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Action_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellAction"]; [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Edit_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellEdit"]; [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Enum_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellEnum"]; [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Image_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellImg"]; [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Label_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellLabel"]; [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_MAction_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellMAction"]; [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Model_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellModel"]; [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Signature_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellSignature"]; [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Switch_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellSwitch"]; [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_TextView_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellTextView"]; [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Range_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorRangeCell"]; [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Web_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorWebCell"]; [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Banner_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorBannerCell"]; [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Editor_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellEditor"]; } - (void)registerPadCell { [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorCellAction" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellAction"]; [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorCellEdit" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellEdit"]; [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorCellEnum" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellEnum"]; [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorCellImg" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellImg"]; [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorCellLabel" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellLabel"]; [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorCellMAction" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellMAction"]; [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorCellModel" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellModel"]; [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorCellSignature" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellSignature"]; [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorCellSwitch" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellSwitch"]; [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorCellTextView" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellTextView"]; // [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorRangeCell" bundle:nil] forCellReuseIdentifier:@"CommonEditorRangeCell"]; // [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorWebCell" bundle:nil] forCellReuseIdentifier:@"CommonEditorWebCell"]; // [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorBannerCell" bundle:nil] forCellReuseIdentifier:@"CommonEditorBannerCell"]; } - (void)setupEditorTable { [self initTableView]; // Regist Nib Cell NSString *model = [UIDevice currentDevice].model; if ([model isEqualToString:@"iPhone"]) { [self registerPhoneCell]; } else { [self registerPadCell]; } } #pragma mark ============== -(void) commonAction:(NSString *)value index:(NSIndexPath*) indexPath data:(NSMutableDictionary*) item_json { NSAssert(true, ([NSString stringWithFormat:@"%@ commonAction not impl",[self class_name]])); } - (NSString *)class_name { if (!_class_name) { const char *class_name_ch = object_getClassName([self class]); _class_name = [NSString stringWithUTF8String:class_name_ch]; } return _class_name; } - (NSString *)urgency_timer_name { if (!_urgency_timer_name) { _urgency_timer_name = [NSString stringWithFormat:@"%@_urgency_timer",self.class_name]; } return _urgency_timer_name; } - (int)level { if (_level == -1) { __block AppDelegate *appDelegate = nil; dispatch_async(dispatch_get_main_queue(), ^{ //some UI methods ej appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate]; }); // AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; NSDictionary *urgencyDic = [RASingleton.sharedInstance globalParameterForKey:@"urgencyDic"]; id count = [urgencyDic objectForKey:@"count"]; _level = count == nil ? 0 : [count intValue]; } return _level; } - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void) request_fill { } -(void) viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; // 键盘高度变化通知,ios5.0新增的 //#ifdef __IPHONE_5_0 // float version = [[[UIDevice currentDevice] systemVersion] floatValue]; // if (version >= 5.0) { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidChangeFrame:) name:UIKeyboardDidChangeFrameNotification object:nil]; // } //#endif } -(void) viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [[NSNotificationCenter defaultCenter] removeObserver:self]; if(!self.alert.isBeingDismissed) { [self.alert dismissViewControllerAnimated:YES completion:nil]; NSLog(@"alert dismiss by viewwillDisapper %p",self.alert); } } -(void)manually_refresh { return; UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200]; reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"]; if ([self respondsToSelector:@selector(reload_data)]) [self performSelector:@selector(reload_data) withObject:nil afterDelay:1]; // DebugLog(@"refresh!!!!!!!!"); } -(void)reload_data { [self.lastedit endEditing:true]; [self.lasttextview endEditing:true]; UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200]; [reF endRefreshing]; reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"]; [self refresh:nil discardDirty:true]; } - (void)alertMessage:(NSString *)msg { [RAUtils message_alert:msg title:nil controller:self] ; } -(void)dealloc { [self.autocompleteView removeFromSuperview]; // [self.editorTable removeObserver:self forKeyPath:@"frame"]; } //- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context //{ // // 方式1.匹配keypath // if ([keyPath isEqualToString:@"frame"]) { // // self.autocompleteView.frame = self.editorTable.frame; // } // // //} - (void)viewDidLoad { [super viewDidLoad]; NSString *model = [UIDevice currentDevice].model; if ([model isEqualToString:@"iPhone"]||true) { [self setupEditorTable]; } // else { // // 在键盘事件中,使用tableContainer计算frame 保证屏幕旋转后table height正确 // if (self.tableContainer == nil) { // self.tableContainer = [[CommonEditorTableContainerView alloc] initWithFrame:self.editorTable.frame]; // self.tableContainer.autoresizingMask = self.editorTable.autoresizingMask; // CGRect frame = self.editorTable.frame; // frame.origin.x = 0; // frame.origin.y = 0; // [self.view addSubview:self.tableContainer]; // [self.view sendSubviewToBack:self.tableContainer]; // [self.tableContainer addSubview:self.editorTable]; // } // } NSArray* nibView = [[NSBundle mainBundle] loadNibNamed:@"CommonEditorAutoCompleteView" owner:nil options:nil]; self.autocompleteView = [nibView firstObject]; self.autocompleteView.dataSource = self; // [self.tableContainer addSubview:self.autocompleteView]; [self.navigationController.view addSubview:self.autocompleteView]; self.autocompleteView.frame = self.navigationController.view.frame; // self.autocompleteView.frame = self.editorTable.frame; // [self.editorTable addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:nil]; self.autocompleteView.hidden = true; // [self.view bringSubviewToFront:self.autocompleteView]; // // self.switchlock = [[NSLock alloc] init]; // [self.editorTable setExclusiveTouch:false]; self.editable = NO; if(self.loading_msg==nil) self.loading_msg = @"Please Wait"; if(self.loading_title==nil) self.loading_title = @"Loading..."; // UIRefreshControl *ref = [[UIRefreshControl alloc]init]; // ref.tag = 200 ; // ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"]; // ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7]; // // ref.hidden = true; // [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged]; // // if(!self.disable_dropdown_refresh) // [self.editorTable addSubview:ref]; self.level = -1; if (!self.changed_data) { self.changed_data = [[NSMutableDictionary alloc] init]; } // UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"close", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onCloseClick:)]; // // closeButton.title = @"Close"; // // self.navigationItem.leftBarButtonItem = closeButton; __weak typeof(self) weakself = self; if(self.url_type==URL_REMOTE) { __block UIAlertController * waitalert = [RAUtils waiting_alert:self message:self.loading_msg title:self.loading_title completion:^{ [RADataProvider request_editor:self.request_url params:self.params completionHandler:^(NSMutableDictionary *result) { NSMutableDictionary* editor_json = result; DebugLog(@"data string: %@",[RAConvertor dict2string:editor_json] ); [waitalert dismissViewControllerAnimated:YES completion:^{ if([[editor_json valueForKey:@"result"] intValue]==RESULT_TRUE) { NSArray* arr_menu =editor_json[@"menu"]; if( arr_menu !=nil) { [self injectMenu:arr_menu]; } weakself.content_data_download = [editor_json mutableCopy]; weakself.content_data_control = [weakself translate_json:weakself.content_data_download changed: weakself.changed_data]; // self.content_data = [editor_json mutableCopy]; // self.content_data = [self translate_json:editor_json]; // NSMutableDictionary* content_data1 = [self translate_json:self.content_data]; [weakself download_success]; [weakself.editorTable reloadData]; // NSString * ttt=[self.content_data valueForKey:@"title"] ; weakself.navigationItem.title = [weakself.content_data_download valueForKey:@"title"] ; } else if([[editor_json valueForKey:@"result"] intValue]==RESULT_LOGIN_ON_OTHER_DEVICE) { [[NSNotificationCenter defaultCenter] postNotificationName:RA_NOTIFICATION_KICKOUT object:nil]; } else { [weakself download_failed]; [weakself alertMessage:[editor_json valueForKey:@"err_msg"]]; } }]; }]; }]; self.alert = waitalert; } else if(self.url_type== URL_LOCAL ) { NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:self.request_url ofType:@"json" ]]; NSError *error=nil; self.content_data_download = [[NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error] mutableCopy]; self.content_data_control=[self translate_json:self.content_data_download changed:self.changed_data]; self.navigationItem.title = [self.content_data_download valueForKey:@"title"] ; [self.editorTable reloadData]; // NSString * ttt=[self.content_data valueForKey:@"title"] ; // self.navigationItem.title = [self.content_data_download valueForKey:@"title"] ; } else { self.content_data_control=[self translate_json:self.content_data_download changed: self.changed_data]; [self.editorTable reloadData]; // NSString * ttt=[self.content_data valueForKey:@"title"] ; self.navigationItem.title = [self.content_data_download valueForKey:@"title"] ; } self.requried = [[NSMutableDictionary alloc] init]; self.cancommit = true; // 恢复编辑后重置URL Type,避免刷新Crash if (self.url_type == URL_RESTORE) { self.url_type = URL_REMOTE; } } -(void) injectMenu:(NSArray* ) menu { UIBarButtonItem *menuItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"ic_more_dot"] style:UIBarButtonItemStylePlain target:self action:@selector(menuItemClick:)]; self.injectMenu = menu; // // closeButton.title = @"Close"; // self.navigationItem.rightBarButtonItem = menuItem; } - (void)menuItemClick:(id)sender { NSAssert(true, ([NSString stringWithFormat:@"%@ menuItemClick not impl",[self class_name]])); } -(NSMutableDictionary*) check_cancommit :(bool) alert { [[[UIApplication sharedApplication] keyWindow] endEditing:YES]; // [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder)]; [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil]; self.first_miss_pos = nil; self.cancommit=true; NSMutableArray* fields=[[NSMutableArray alloc] init]; NSMutableDictionary* upparams=[[NSMutableDictionary alloc] init]; // [upparams setValue:[self.params valueForKey:@"cart2Checkbox"] forKey:@"cart2Checkbox"]; int section_count=(int)self.content_data_control.count;//[[self.content_data_download valueForKey:@"section_count"] intValue]; // NSString* aaa = [RAUtils dict2string:self.content_data_control]; for(int i=0;i */ }else if([[itemjson valueForKey:@"control"] isEqualToString:@"action"]) { if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"data"]==nil) { self.cancommit = false; NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,itemjson[@"aname"]]; [fields addObject:mfield]; NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]]; if(alert) [self unhide_section:(int)indexpath.section]; if(fields.count==1) { self.first_miss_pos = indexpath; } } } else if([[itemjson valueForKey:@"control"] isEqualToString:@"signature"]) { if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"value"] ==nil) { self.cancommit = false; NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,itemjson[@"aname"]]; [fields addObject:mfield]; NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]]; if(alert) [self unhide_section:(int)indexpath.section]; if(fields.count==1) { self.first_miss_pos = indexpath; } } NSString* valuestr = [itemjson valueForKey:@"value"]; [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]]; } else if([[itemjson valueForKey:@"control"] isEqualToString:@"switch"]) { NSString* valuestr = [itemjson valueForKey:@"value"]; [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]]; NSString* value = [itemjson valueForKey:@"value"]; NSMutableDictionary* boolitem=nil; NSMutableDictionary* subjson=nil; if([value isEqualToString:@"true"]) { boolitem =[[itemjson objectForKey:@"true"] mutableCopy]; } else { boolitem =[[itemjson objectForKey:@"false"] mutableCopy]; } subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy]; if( subjson!=nil /*&& !active*/) { int sub_count = [[subjson valueForKey:@"count"] intValue]; for(int l=0;l 0) { // key NSString *max_key = [itemjson objectForKey:@"max"]; id max_obj = [self downloadValueForKey:max_key]; if (max_obj) { max_value = [max_obj floatValue]; } } else { // value id max_obj = [itemjson objectForKey:@"max"]; if (max_obj != nil) { max_value = [max_obj floatValue]; } } if (max_value < f_value) { mfield =[NSString stringWithFormat:@"%ld. the value of %@ must be not larger than %.2f",fields.count+1,itemjson[@"aname"],max_value]; } } if (check_min) { if (min_type > 0) { // key NSString *min_key = [itemjson objectForKey:@"min"]; id min_obj = [self downloadValueForKey:min_key]; if (min_obj) { min_value = [min_obj floatValue]; } } else { // value id min_obj = [itemjson objectForKey:@"min"]; if (min_obj != nil) { min_value = [min_obj floatValue]; } } if (min_value > f_value) { mfield =[NSString stringWithFormat:@"%ld. the value of %@ must be not smaller than %.2f",fields.count+1,itemjson[@"aname"],min_value]; } } if (check_min && check_max) { if (f_value < min_value || f_value > max_value) { mfield =[NSString stringWithFormat:@"%ld. the value of %@ must between %.2f and %.2f",fields.count+1,itemjson[@"aname"],min_value,max_value]; } } if (mfield != nil) { self.cancommit = false; [fields addObject:mfield]; NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]]; if(alert) [self unhide_section:(int)indexpath.section]; if(fields.count==1) { self.first_miss_pos = indexpath; } } else { [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]]; } } else { [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]]; } } else { if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] ) { self.cancommit = false; NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,itemjson[@"aname"]]; [fields addObject:mfield]; NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]]; if(alert) [self unhide_section:(int)indexpath.section]; if(fields.count==1) { self.first_miss_pos = indexpath; } } } } else if ([[itemjson valueForKey:@"control"] isEqualToString:@"range"]) { if([itemjson valueForKey:@"min_value"]!=nil && ![[itemjson valueForKey:@"min_value"]isEqualToString:@""] &&[itemjson valueForKey:@"max_value"]!=nil && ![[itemjson valueForKey:@"max_value"]isEqualToString:@""]) { NSMutableDictionary* valjson = [NSMutableDictionary new]; if([itemjson valueForKey:@"min_value"]!=nil && ![[itemjson valueForKey:@"min_value"]isEqualToString:@""]) valjson[@"min"] = itemjson[@"min_value"]; if([itemjson valueForKey:@"max_value"]!=nil && ![[itemjson valueForKey:@"max_value"]isEqualToString:@""]) valjson[@"max"] = itemjson[@"max_value"]; NSString* val=[RAConvertor dict2string:valjson]; // NSString *keyboard_type = [itemjson objectForKey:@"keyboard"]; // BOOL check_max = [itemjson objectForKey:@"max_type"] != nil ? YES : NO; // BOOL check_min = [itemjson objectForKey:@"min_type"] != nil ? YES : NO; // if ([keyboard_type isEqualToString:@"number"] && (check_max || check_min)) { // // 检查最大值最小值 // int max_type = [[itemjson objectForKey:@"max_type"] intValue]; // int min_type = [[itemjson objectForKey:@"min_type"] intValue]; // // float max_value = MAXFLOAT; // float min_value = 0; // // NSString *mfield = nil; //// float f_value = [check_len_val floatValue]; //// //// if (check_max) { //// //// if (max_type > 0) { //// // key //// NSString *max_key = [itemjson objectForKey:@"max"]; //// id max_obj = [self downloadValueForKey:max_key]; //// if (max_obj) { //// max_value = [max_obj floatValue]; //// } //// //// } else { //// // value //// id max_obj = [itemjson objectForKey:@"max"]; //// if (max_obj != nil) { //// max_value = [max_obj floatValue]; //// } //// //// } //// //// if (max_value < f_value) { //// mfield =[NSString stringWithFormat:@"%ld. the value of %@ must be not larger than %.2f",fields.count+1,itemjson[@"aname"],max_value]; //// } //// } // //// if (check_min) { //// //// if (min_type > 0) { //// // key //// NSString *min_key = [itemjson objectForKey:@"min"]; //// id min_obj = [self downloadValueForKey:min_key]; //// if (min_obj) { //// min_value = [min_obj floatValue]; //// } //// } else { //// // value //// id min_obj = [itemjson objectForKey:@"min"]; //// if (min_obj != nil) { //// min_value = [min_obj floatValue]; //// } //// } //// //// if (min_value > f_value) { //// mfield =[NSString stringWithFormat:@"%ld. the value of %@ must be not smaller than %.2f",fields.count+1,itemjson[@"aname"],min_value]; //// } //// } // // //// if (check_min && check_max) { //// if (f_value < min_value || f_value > max_value) { //// mfield =[NSString stringWithFormat:@"%ld. the value of %@ must between %.2f and %.2f",fields.count+1,itemjson[@"aname"],min_value,max_value]; //// } //// } // // if (mfield != nil) { // self.cancommit = false; // [fields addObject:mfield]; // NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]]; // if(alert) // [self unhide_section:(int)indexpath.section]; // if(fields.count==1) // { // self.first_miss_pos = indexpath; // // } // } else { // [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]]; // } // // } else // { [upparams setValue:val forKey:[itemjson valueForKey:@"name"]]; // } } else { if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] ) { self.cancommit = false; NSString* mfield =[NSString stringWithFormat:@"%lu. %@ is missing",fields.count+1,itemjson[@"aname"]]; [fields addObject:mfield]; NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]]; if(alert) [self unhide_section:(int)indexpath.section]; if(fields.count==1) { self.first_miss_pos = indexpath; } } } } else { if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""]) [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]]; else { if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] ) { self.cancommit = false; NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,itemjson[@"aname"]]; [fields addObject:mfield]; NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]]; if(alert) [self unhide_section:(int)indexpath.section]; if(fields.count==1) { self.first_miss_pos = indexpath; } } } } // subitem_data * data=[self subitem_param:itemjson addto:upparams alert:alert]; // upparams= data.params; // fields=[[fields arrayByAddingObjectsFromArray:data.missingfields] mutableCopy]; } } if(self.cancommit==false && alert) { NSString* missfields=[fields componentsJoinedByString:@"\n"]; NSString* msg = [NSString stringWithFormat:@"%@",missfields]; CustomIOSAlertView *alertView = [[CustomIOSAlertView alloc] init]; // Add some custom content to the alert view [alertView setContainerView:[self createDemoView:msg]]; // Modify the parameters [alertView setButtonTitles:[NSMutableArray arrayWithObjects:@"OK", nil]]; //[alertView setDelegate:self]; // You may use a Block, rather than a delegate. [alertView setOnButtonTouchUpInside:^(CustomIOSAlertView *alertView, int buttonIndex) { // DebugLog(@"Block: Button at position %d is clicked on alertView %d.", buttonIndex, (int)[alertView tag]); [alertView close]; }]; // [alertView setUseMotionEffects:true]; // And launch the dialog [alertView sizeToFit]; [alertView show]; // [RAUtils alert_view:msg title:@"Please complete missing fields:"]; self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data]; [self.editorTable reloadData]; [self.editorTable scrollToRowAtIndexPath:self.first_miss_pos atScrollPosition:UITableViewScrollPositionMiddle animated:YES]; return upparams; } else { self.cancommit=true; //[self.editorTable reloadData]; } return upparams; } - (UIView *)createDemoView:(NSString*) msg { UIView *demoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 290, 200)]; // UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 270, 180)]; // [imageView setImage:[UIImage imageNamed:@"demo"]]; UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 270, 10)]; titleLabel.font = [UIFont boldSystemFontOfSize:20]; titleLabel.text=@"Please complete missing fields:"; titleLabel.numberOfLines = 0; titleLabel.lineBreakMode =NSLineBreakByWordWrapping; // titleLabel.textAlignment = NSTextAlignmentRight; titleLabel.textAlignment = NSTextAlignmentCenter; CGSize constraintkey = CGSizeMake(270, 20000.0f);//key label width is 40% cell width; // CGSize sizetitle = [@"Please complete missing fields:" sizeWithFont:[UIFont systemFontOfSize:20.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping]; // CGSize sizetitle = [RAUtils sizeWithFont:@"Please complete missing fields:" font:[UIFont systemFontOfSize:20.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping]; //[titleLabel sizeToFit]; // titleLabel.center.x = demoView.center.x; titleLabel.frame = CGRectMake(10, 10, 270, sizetitle.height); [demoView addSubview:titleLabel]; UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 260, 10)]; lineLabel.font = [UIFont boldSystemFontOfSize:17]; lineLabel.text=msg; lineLabel.numberOfLines = 0; lineLabel.lineBreakMode =NSLineBreakByWordWrapping; // CGSize sizemsg = [msg sizeWithFont:[UIFont boldSystemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping]; CGSize sizemsg = [RAUtils sizeWithFont:msg font:[UIFont boldSystemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping]; lineLabel.frame = CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 260, sizemsg.height); //[lineLabel sizeToFit]; [demoView addSubview:lineLabel]; demoView.frame = CGRectMake(0, 0, 290, lineLabel.frame.origin.y+lineLabel.frame.size.height+25); return demoView; } //- (void)willPresentAlertView:(UIAlertView *)alertView{ // // // alertView set // for( UIView * view in alertView.subviews ) // // { if( [view isKindOfClass:[UILabel class]] ) // // { UILabel* label = (UILabel*) view; // // label.textAlignment = NSTextAlignmentLeft; } // // } // //} //-(bool) action_btn_passed_check:(NSDictionary* ) data; //{ // if(data == nil) // return false; // int section_count=[[data valueForKey:@"section_count"] intValue]; // // for(int sc=0;sc */ } else { if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""]) [upparam setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]]; else { if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] ) { self.cancommit = false; NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,itemjson[@"aname"]]; [fields addObject:mfield]; NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]]; if(alert) [self unhide_section:(int)indexpath.section]; if(fields.count==1) { self.first_miss_pos = indexpath; } } } } subitem_data * data1=[self subitem_param:itemjson addto:upparam alert:alert]; upparam= data1.params; fields=[[fields arrayByAddingObjectsFromArray:data1.missingfields] mutableCopy]; // upparam= [self subitem_param:itemjson addto:upparam ]; } } } else { if([addjson valueForKey:@"value"]!=nil && ![[addjson valueForKey:@"value"]isEqualToString:@""]) [upparam setValue:[addjson valueForKey:@"value"] forKey:key]; else { if([[addjson valueForKey:@"required"] isEqualToString: @"true"] ) { self.cancommit = false; NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,addjson[@"aname"]]; [fields addObject:mfield]; NSIndexPath* indexpath =[self get_indexpath1:[addjson valueForKey:@"name"]]; if(alert) [self unhide_section:(int)indexpath.section]; if(fields.count==1) { self.first_miss_pos = indexpath; } } } } subitem_data * data2=[self subitem_param:addjson addto:upparam alert:alert]; upparam= data2.params; fields=[[fields arrayByAddingObjectsFromArray:data2.missingfields] mutableCopy]; //upparam=[self subitem_param:addjson addto:upparam]; // [sectionjson setObject: addjson forKey:[NSString stringWithFormat:@"item_%d",item_count ]]; // item_count ++; // [addjson setValue:[NSString stringWithFormat:@"val_%d",k ]] forKey:@"parent"]; } //break; } } } data.params = upparam; data.missingfields = fields; return data; } -(NSMutableArray*) add_subitem:(NSDictionary*) itemjson addto:(NSMutableArray*) sectionarr parent:(NSString*) parent { NSString * control_type = [itemjson valueForKey:@"control"]; bool single_select = [[itemjson valueForKey:@"single_select"] boolValue]; if([control_type isEqual:@"enum"] && single_select) { NSMutableDictionary * cadedatejson=[[itemjson objectForKey:@"cadedate"] mutableCopy]; int cade_count = [[cadedatejson valueForKey:@"count"] intValue]; for(int k=0;k)#> // return nil; } } /* -(NSMutableDictionary*) translate_json: (NSDictionary*) injson { if(injson == nil) return nil; NSMutableDictionary * retjson= [injson mutableCopy]; int section_count=[[retjson valueForKey:@"section_count"] intValue]; for(int i=0;i)#> return nil; }*/ //- (void)onCloseClick:(UIButton *)sender { // [self.navigationController dismissViewControllerAnimated:true completion:^{ // ; // }]; //} - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(void) prepareReturn:(NSMutableDictionary*) value { if(value==nil) value=[[NSMutableDictionary alloc]init]; value[@"is_subaction"] = self.params[@"is_subaction"]; value[@"subaction_tag"] = self.params[@"subaction_tag"]; if (self.delegate && [self.delegate respondsToSelector:@selector(returnValue:indexPath:)]) { [self.delegate returnValue:value indexPath:self.from]; } if(self.returnValue) self.returnValue(nil); } -(void) handle_action_return:(NSMutableDictionary *)value indexPath :(NSIndexPath*) indexPath action:(int) action_code { DebugLog(@"commoneditor return %ld_%ld",(long)indexPath.section,(long)indexPath.row); NSMutableDictionary* section_json=nil; NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy]; bool is_subaction = [value[@"is_subaction"] boolValue]; int subaction_tag= [value[@"subaction_tag"] intValue]; [value removeObjectForKey:@"is_subaction"]; [value removeObjectForKey:@"subaction_tag"]; if(is_subaction) { NSMutableDictionary* sub_action = [[item_json objectForKey:[NSString stringWithFormat:@"item_%d",subaction_tag]] mutableCopy]; bool refresh = [[sub_action valueForKey:@"refresh"] boolValue]; bool discardDirty = [[sub_action valueForKey:@"discard_dirty"] boolValue]; NSString* refresh_trigger = [sub_action valueForKey:@"name"]; NSDictionary * restore_json=[sub_action objectForKeyedSubscript:@"restore"]; NSString* subid=[sub_action valueForKey:@"subid"]; UITableViewCell *cell = [self.editorTable cellForRowAtIndexPath:indexPath]; NSString* required = [sub_action valueForKey:@"required"]; if([required isEqualToString:@"true"] && value.count==0) { CALayer *layer = [cell.contentView layer]; // layer.borderColor = [[UIColor redColor] CGColor]; // layer.borderWidth = 1.0; layer.shadowColor = [UIColor redColor].CGColor; layer.shadowOffset = CGSizeMake(0, 0); layer.shadowOpacity = 1; layer.shadowRadius = 2.0; } else { CALayer *layer = [cell.contentView layer]; // layer.borderColor = [[UIColor redColor] CGColor]; // layer.borderWidth = 1.0; layer.shadowColor = [UIColor clearColor].CGColor; layer.shadowOffset = CGSizeMake(0, 0); layer.shadowOpacity = 1; layer.shadowRadius = 2.0; } if(value.count!=0) { if(action_code==ACTION_SAVE_DATA) { [sub_action setObject:value forKey:@"data"]; if(subid==nil) { [sub_action setValue:@"true" forKey:@"dirty"]; section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy]; int count=0; count=[[section_json valueForKey:@"count"] intValue]; for(int i=0;i0) // return 1; return self.content_data_control.count; // int section_count =[[self.content_data valueForKey:@"section_count"] intValue]; // return section_count; } //- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath //{ // DebugLog(@"canMoveRowAtIndexPath"); // // if([tableView numberOfRowsInSection:indexPath.section]>1) // 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(self.content_data_control.count>0) // return 1; NSMutableDictionary* sectionjson= [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)section]] mutableCopy]; bool hide = [[sectionjson valueForKey:@"hide"]boolValue]; if(hide) { return 0; // [sectionjson setValue:@"false" forKey:@"hide"]; // [sender setTitle:@"Show" forState:UIControlStateNormal]; } else{ return ((NSMutableArray*)self.content_data_control[section]).count; // [sectionjson setValue:@"true" forKey:@"hide"]; // [sender setTitle:@"Hide" forState:UIControlStateNormal]; } // return 0; // if(section==4) // return 1; // NSMutableDictionary* section_json = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",(long)section ]]; // // return [[section_json valueForKey:@"count" ] intValue]; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { if(section==0) return 44; return 33; } //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section //{ // return 0.5; //} - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath; { NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row]; NSString* control = [item_json valueForKey:@"control"]; NSString *model = [UIDevice currentDevice].model; if ([model isEqualToString:@"iPhone"]) { if([control isEqualToString:@"model"]) return 140; else if([control isEqualToString:@"signature"]) return 200; else if([control isEqualToString:@"text_view"]) return 180; else if([control isEqualToString:@"img"]) return 240; else if ([control isEqualToString:@"action"]) return 44; else if ([control isEqualToString:@"text"]) return 80; else if ([control isEqualToString:@"enum"]) return 80; else if ([control isEqualToString:@"edit"]) return 80; else if ([control isEqualToString:@"switch"]) return 80; else if([control isEqualToString:@"multi_action"]) { int count = [[item_json valueForKey:@"count"]intValue]; if (count <= 2) { return 50; } else { return 100; } } else if ([control isEqualToString:@"webview"]) { id h_obj = [item_json objectForKey:@"height"]; CGFloat height = [h_obj floatValue]; if(height<44) height=44; return height; } else if ([control isEqualToString:@"banner"]) { return 200; } return 80; } else { if([control isEqualToString:@"model"]) return 140; else if([control isEqualToString:@"signature"]) return 140; else if([control isEqualToString:@"text_view"]) return 140; else if([control isEqualToString:@"img"]) return 123; return 44; } } // - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { bool readonly = [[self.content_data_download valueForKey:@"readonly"]boolValue]; // int d=0; // if(indexPath.section==4) // d=0; // DebugLog(@"%d,%d",indexPath.section,indexPath.row); // NSMutableDictionary* section_json = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]]; AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row]; NSString* control = [item_json valueForKey:@"control"]; NSString* required = [item_json valueForKey:@"required"]; NSString *CellIdentifier = @""; if([control isEqualToString:@"text_view"]) { CellIdentifier = @"CommonEditorCellTextView"; CommonEditorCellTextView * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy]; NSString* value =[item_json valueForKey:@"value"]; NSString* align =[item_json valueForKey:@"align"]; if([align isEqualToString:@"right"]) cell.textview.textAlignment= kCTTextAlignmentRight; else cell.textview.textAlignment =kCTTextAlignmentLeft; int capital =[[item_json valueForKey:@"capital"] intValue]; switch (capital) { case 1: cell.textview.autocapitalizationType=UITextAutocapitalizationTypeWords; break; case 2: cell.textview.autocapitalizationType=UITextAutocapitalizationTypeSentences; break; case 3: cell.textview.autocapitalizationType=UITextAutocapitalizationTypeAllCharacters; break; default: cell.textview.autocapitalizationType=UITextAutocapitalizationTypeWords;//UITextAutocapitalizationTypeNone; break; } int disable = [[item_json valueForKey:@"disable"] intValue]; if(disable==1||readonly) { cell.textview.editable=NO; // cell.textfield.backgroundColor = [UIColor lightGrayColor]; cell.textview.textColor= [UIColor lightGrayColor]; } else { cell.textview.editable=YES; cell.textview.textColor= [UIColor blackColor]; // cell.textfield.backgroundColor = [UIColor whiteColor]; } // if([required isEqualToString:@"true"]) // { // [title appendString:@"*"]; // } cell.label_name.text=title; if([required isEqualToString:@"true"]) { [cell.label_name sizeToFit]; CGRect frame =cell.label_name.frame; frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21); cell.starMark.frame = frame; cell.starMark.hidden=false; // [title appendString:@"*"]; // [title appendString:@"*"]; // NSString * htmlString = @" Some html string \n This is some text! "; } else { [cell.label_name sizeToFit]; cell.starMark.hidden=true; } cell.textview.text = value; cell.textview.delegate = self; cell.accessoryType = UITableViewCellAccessoryNone; if(self.cancommit==false && [required isEqualToString:@"true"] && (value==nil || value.length==0)) { CALayer *layer = [cell.contentView layer]; // layer.borderColor = [[UIColor redColor] CGColor]; // layer.borderWidth = 1.0; layer.shadowColor = [UIColor redColor].CGColor; layer.shadowOffset = CGSizeMake(0, 0); layer.shadowOpacity = 1; layer.shadowRadius = 2.0; } else { CALayer *layer = [cell.contentView layer]; // layer.borderColor = [[UIColor redColor] CGColor]; // layer.borderWidth = 1.0; layer.shadowColor = [UIColor clearColor].CGColor; layer.shadowOffset = CGSizeMake(0, 0); layer.shadowOpacity = 1; } cell.backgroundColor = [UIColor whiteColor]; return cell; }else if([control isEqualToString:@"img"]) { CellIdentifier = @"CommonEditorCellImg"; CommonEditorCellImg * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; cell.touchImageView0.contentMode = UIViewContentModeScaleAspectFit; cell.touchImageView1.contentMode = UIViewContentModeScaleAspectFit; cell.touchImageView2.contentMode = UIViewContentModeScaleAspectFit; NSString* title = [item_json valueForKey:@"aname"] ; NSString* value =[item_json valueForKey:@"value"]; int disable = [[item_json valueForKey:@"disable"] intValue]; if(disable==1||readonly) { cell.editable=false; } else cell.editable=true; cell.labelTitle.text = title; cell.labelDescription.text = value; __weak typeof(self) weakself = self; cell.imgChanged = ^(NSString* url_down,NSString* url_up,int index ,NSString* url_index) { // NSMutableDictionary* editjson = [item_json mutableCopy]; // editjson[@"img_url"]=url; [weakself imgIsChanged:url_down url_up:url_up indexPath:indexPath index:index url_index:url_index]; }; { NSString* img_url0 = [item_json valueForKey:@"img_url_0"]; if(img_url0.length>0) { NSString* img_url_up=[item_json valueForKey:@"img_url_aname_0"]; if(img_url_up.length==0) img_url_up=@""; cell.imgs[0]=img_url_up; NSString* file_name=[img_url0 lastPathComponent]; NSData* img_data=[FileCache load_cached_img:file_name loadFrom:img_url0]; if(img_data!=nil) { UIImage * img =[UIImage imageWithData:img_data]; cell.touchImageView0.image=img; cell.img_validate = true; // [cell.touchImageView setImage:img forState:UIControlStateNormal]; } else { // __weak typeof(self) weakself = self; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url0]]; dispatch_async(dispatch_get_main_queue(), ^{ if(downloadimg_data!=nil) { [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url0]; UIImage * img =[UIImage imageWithData:downloadimg_data]; cell.touchImageView0.image=img; cell.img_validate = true; } else { cell.touchImageView0.image=[UIImage imageNamed:@"notfound_s"]; cell.img_validate = false; } }); }); } } else { cell.touchImageView0.image=nil; cell.imgs[0]=@""; } } { NSString* img_url1 = [item_json valueForKey:@"img_url_1"]; if(img_url1.length>0) { NSString* img_url_up=[item_json valueForKey:@"img_url_aname_1"]; if(img_url_up.length==0) img_url_up=@""; cell.imgs[1]=img_url_up; NSString* file_name=[img_url1 lastPathComponent]; NSData* img_data=[FileCache load_cached_img:file_name loadFrom:img_url1]; if(img_data!=nil) { UIImage * img =[UIImage imageWithData:img_data]; cell.touchImageView1.image=img; cell.img_validate = true; // [cell.touchImageView setImage:img forState:UIControlStateNormal]; } else { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url1]]; dispatch_async(dispatch_get_main_queue(), ^{ if(downloadimg_data!=nil) { [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url1]; UIImage * img =[UIImage imageWithData:downloadimg_data]; cell.touchImageView1.image=img; cell.img_validate = true; } else { cell.touchImageView1.image=[UIImage imageNamed:@"notfound_s"] ; cell.img_validate = false; } }); }); } } else { cell.touchImageView1.image=nil; cell.imgs[1]=@""; } } { NSString* img_url2 = [item_json valueForKey:@"img_url_2"]; if(img_url2.length>0) { NSString* img_url_up=[item_json valueForKey:@"img_url_aname_2"]; if(img_url_up.length==0) img_url_up=@""; cell.imgs[2]=img_url_up; NSString* file_name=[img_url2 lastPathComponent]; NSData* img_data=[FileCache load_cached_img:file_name loadFrom:img_url2]; if(img_data!=nil) { UIImage * img =[UIImage imageWithData:img_data]; cell.touchImageView2.image=img; cell.img_validate = true; // [cell.touchImageView setImage:img forState:UIControlStateNormal]; } else { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url2]]; dispatch_async(dispatch_get_main_queue(), ^{ if(downloadimg_data!=nil) { [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url2]; UIImage * img =[UIImage imageWithData:downloadimg_data]; cell.touchImageView2.image=img; cell.img_validate = true; } else { cell.touchImageView2.image=[UIImage imageNamed:@"notfound_s"] ; cell.img_validate = false; } }); }); }} else { cell.touchImageView2.image=nil; cell.imgs[2]=@""; } } cell.backgroundColor = [UIColor whiteColor]; return cell; }else if([control isEqualToString:@"edit"]) { CellIdentifier = @"CommonEditorCellEdit"; CommonEditorCellEdit * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy]; // title =[[NSString stringWithFormat:@"%@",title] mutableCopy]; NSString* value =[item_json valueForKey:@"value"]; NSString* align =[item_json valueForKey:@"align"]; if([align isEqualToString:@"right"]) cell.textfield.textAlignment= NSTextAlignmentRight; else cell.textfield.textAlignment =NSTextAlignmentLeft; int capital =[[item_json valueForKey:@"capital"] intValue]; switch (capital) { case 1: cell.textfield.autocapitalizationType=UITextAutocapitalizationTypeWords; break; case 2: cell.textfield.autocapitalizationType=UITextAutocapitalizationTypeSentences; break; case 3: cell.textfield.autocapitalizationType=UITextAutocapitalizationTypeAllCharacters; break; default: cell.textfield.autocapitalizationType=UITextAutocapitalizationTypeWords;//UITextAutocapitalizationTypeNone; break; } int disable = [[item_json valueForKey:@"disable"] intValue]; if(disable==1||readonly) { cell.textfield.enabled=NO; // cell.textfield.backgroundColor = [UIColor lightGrayColor]; cell.textfield.textColor= [UIColor lightGrayColor]; } else { cell.textfield.enabled=YES; cell.textfield.textColor= [UIColor blackColor]; // cell.textfield.backgroundColor = [UIColor whiteColor]; } NSString* keyboard = [item_json valueForKey:@"keyboard"]; if([keyboard isEqualToString:@"number"]) { // float f = [value floatValue]; // value = [NSString stringWithFormat:@"%.2f",f]; cell.textfield.keyboardType=UIKeyboardTypeDecimalPad; // cell.textfield.keyboardType=UIKeyboardTypeNumbersAndPunctuation; } else if([keyboard isEqualToString:@"int"]) { // float f = [value floatValue]; // value = [NSString stringWithFormat:@"%.2f",f]; cell.textfield.keyboardType=UIKeyboardTypeNumberPad; // cell.textfield.keyboardType=UIKeyboardTypeNumbersAndPunctuation; } else if([keyboard isEqualToString:@"email"]) { cell.textfield.keyboardType=UIKeyboardTypeEmailAddress; } else if([keyboard isEqualToString:@"phone"]) { cell.textfield.keyboardType=UIKeyboardTypePhonePad; } else { cell.textfield.keyboardType=UIKeyboardTypeDefault; } // UIKIT_EXTERN NSString * const NSPlainTextDocumentType NS_AVAILABLE(10_0, 7_0); // UIKIT_EXTERN NSString * const NSRTFTextDocumentType NS_AVAILABLE(10_0, 7_0); // UIKIT_EXTERN NSString * const NSRTFDTextDocumentType NS_AVAILABLE(10_0, 7_0); // UIKIT_EXTERN NSString * const NSHTMLTextDocumentType NS_AVAILABLE(10_0, 7_0); // // NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[title dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil]; // UILabel * myLabel = [[UILabel alloc] initWithFrame:self.view.bounds]; // myLabel.attributedText = attrStr; // cell.labelTitle.attributedText = attrStr; cell.labelTitle.text=title; if([required isEqualToString:@"true"]) { [cell.labelTitle sizeToFit]; CGRect frame =cell.labelTitle.frame; frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21); cell.starMark.frame = frame; cell.starMark.hidden=false; // [title appendString:@"*"]; // [title appendString:@"*"]; // NSString * htmlString = @" Some html string \n This is some text! "; } else { [cell.labelTitle sizeToFit]; cell.starMark.hidden=true; } cell.textfield.text = value; cell.textfield.delegate = self; cell.accessoryType = UITableViewCellAccessoryNone; if(self.cancommit==false && [required isEqualToString:@"true"] && (value==nil || value.length==0)) { CALayer *layer = cell.labelTitle.layer; // layer.borderColor = [[UIColor redColor] CGColor]; // layer.borderWidth = 1.0; layer.shadowColor = [UIColor redColor].CGColor; layer.shadowOffset = CGSizeMake(0, 0); layer.shadowOpacity = 1; layer.shadowRadius = 2.0; layer = cell.starMark.layer; // layer.borderColor = [[UIColor redColor] CGColor]; // layer.borderWidth = 1.0; layer.shadowColor = [UIColor redColor].CGColor; layer.shadowOffset = CGSizeMake(0, 0); layer.shadowOpacity = 1; layer.shadowRadius = 2.0; //UIImageView * iv = cell.textfield.rightView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"mark_attention_24"]]; cell.textfield.rightViewMode=UITextFieldViewModeUnlessEditing; cell.textfield.layer.cornerRadius=8.0f; cell.textfield.layer.borderWidth= 1.0f; cell.textfield.layer.masksToBounds=YES; cell.textfield.layer.borderColor=[[UIColor redColor]CGColor]; } else { CALayer *layer = cell.labelTitle.layer;//[cell.contentView layer]; // layer.borderColor = [[UIColor redColor] CGColor]; // layer.borderWidth = 1.0; layer.shadowColor = [UIColor clearColor].CGColor; layer.shadowOffset = CGSizeMake(0, 0); layer.shadowOpacity = 1; layer = cell.starMark.layer;//[cell.contentView layer]; // layer.borderColor = [[UIColor redColor] CGColor]; // layer.borderWidth = 1.0; layer.shadowColor = [UIColor clearColor].CGColor; layer.shadowOffset = CGSizeMake(0, 0); layer.shadowOpacity = 1; cell.textfield.rightViewMode=UITextFieldViewModeNever; //cell.textfield.layer.borderColor= [[UIColor lightGrayColor] CGColor]; cell.textfield.rightView = nil; cell.textfield.layer.cornerRadius=8.0f; cell.textfield.layer.borderWidth= 1.0f; cell.textfield.layer.masksToBounds=YES; cell.textfield.layer.borderColor=[[UIColor lightGrayColor]CGColor]; } cell.backgroundColor = [UIColor whiteColor]; return cell; } else if([control isEqualToString:@"text"]) { CellIdentifier = @"CommonEditorCellLabel"; CommonEditorCellLabel * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; //CGRect titleframe = cell.labelTitle.frame; NSString* title = [item_json valueForKey:@"aname"] ; NSString* value =[item_json valueForKey:@"value"]; NSString* color =[item_json valueForKey:@"color"]; cell.labelValue.textColor = [RAUtils strColor:color]; NSString* align =[item_json valueForKey:@"align"]; if([align isEqualToString:@"right"]) { cell.labelTitle.frame =CGRectMake(15,11,350,21); cell.labelValue.textAlignment= NSTextAlignmentRight; } else { cell.labelTitle.frame =CGRectMake(15,11,150,21); cell.labelValue.textAlignment =NSTextAlignmentLeft; } NSString* type=[item_json valueForKey:@"type"] ; // 此处应移动到erp mobile 项目内 if([type isEqualToString:@"price"]) { BOOL can_see_price = [[RASingleton.sharedInstance globalParameterForKey:@"can_see_price"] boolValue]; BOOL price_hidden = [[RASingleton.sharedInstance globalParameterForKey:@"price_hidden"] boolValue]; if(can_see_price&&price_hidden==false) { } else { value=nil; } } cell.labelTitle.text=title; cell.labelValue.text = value; cell.backgroundColor = [UIColor whiteColor]; return cell; } else if([control isEqualToString:@"action"]) { CellIdentifier = @"CommonEditorCellAction"; CommonEditorCellAction * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; int disable = [[item_json valueForKey:@"disable"] intValue]; if(disable==1||readonly) { cell.labelAction.textColor= [UIColor lightGrayColor]; } else { cell.labelAction.textColor= [UIColor blackColor]; } NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy]; NSString* value =[item_json valueForKey:@"value"]; if([required isEqualToString:@"true"]) { [title appendString:@"*"]; } NSDictionary* data = [item_json objectForKey:@"data"]; cell.labelAction.text=title; cell.action_code = value; //cell.labelValue.text = value; if(self.cancommit==false && [required isEqualToString:@"true"] && (data==nil)) { CALayer *layer = [cell.contentView layer]; // layer.borderColor = [[UIColor redColor] CGColor]; // layer.borderWidth = 1.0; layer.shadowColor = [UIColor redColor].CGColor; layer.shadowOffset = CGSizeMake(0, 0); layer.shadowOpacity = 1; layer.shadowRadius = 2.0; } else { CALayer *layer = [cell.contentView layer]; // layer.borderColor = [[UIColor redColor] CGColor]; // layer.borderWidth = 1.0; layer.shadowColor = [UIColor clearColor].CGColor; layer.shadowOffset = CGSizeMake(0, 0); layer.shadowOpacity = 1; } cell.backgroundColor = [UIColor whiteColor]; return cell; } if([control isEqualToString:@"multi_action"]) { CellIdentifier = @"CommonEditorCellMAction"; CommonEditorCellMAction * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; int count = [[item_json valueForKey:@"count"]intValue]; for(int i=0;i*"]; // NSString * htmlString = @" Some html string \n This is some text! "; } else { [cell.labelTitle sizeToFit]; cell.starMark.hidden=true; } [cell.switchCtrl addTarget:self action:@selector(switchIsChanged:) forControlEvents:UIControlEventValueChanged]; if([[value lowercaseString] isEqualToString:@"true"]) cell.switchCtrl.on = true; else cell.switchCtrl.on = false; cell.accessoryType = UITableViewCellAccessoryNone; cell.backgroundColor = [UIColor whiteColor]; return cell; } else if([control isEqualToString:@"editor"]) { CellIdentifier = @"CommonEditorCellEditor"; CommonEditorCellEditor * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; NSString* title = [[item_json valueForKey:@"aname"] stringValue]; NSString* value = [[item_json valueForKey:@"value"] stringValue]; int disable = [[item_json valueForKey:@"disable"] intValue]; if(disable==1||readonly) { cell.labelValue.textColor= [UIColor lightGrayColor]; } else { cell.labelValue.textColor= [UIColor blackColor]; // cell.textfield.backgroundColor = [UIColor whiteColor]; } NSString* align =[item_json valueForKey:@"align"]; if([align isEqualToString:@"right"]) cell.labelValue.textAlignment= NSTextAlignmentRight; else cell.labelValue.textAlignment =NSTextAlignmentLeft; cell.labelName.text=title; cell.labelValue.text=value; // if([required isEqualToString:@"true"]) // { // [cell.labelTitle sizeToFit]; // CGRect frame =cell.labelTitle.frame; // frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21); // cell.starMark.frame = frame; // cell.starMark.hidden=false; // // [title appendString:@"*"]; // // // [title appendString:@"*"]; // // NSString * htmlString = @" Some html string \n This is some text! "; // } // else // { // [cell.labelTitle sizeToFit]; // cell.starMark.hidden=true; // } cell.backgroundColor = [UIColor whiteColor]; return cell; } else if([control isEqualToString:@"enum"]) { CellIdentifier = @"CommonEditorCellEnum"; CommonEditorCellEnum * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy]; NSDictionary* cadedate_json =[item_json objectForKey:@"cadedate"]; int disable = [[item_json valueForKey:@"disable"] intValue]; if(disable==1||readonly) { cell.labelValue.textColor= [UIColor lightGrayColor]; } else { cell.labelValue.textColor= [UIColor blackColor]; // cell.textfield.backgroundColor = [UIColor whiteColor]; } NSString* align =[item_json valueForKey:@"align"]; if([align isEqualToString:@"right"]) cell.labelValue.textAlignment= NSTextAlignmentRight; else cell.labelValue.textAlignment =NSTextAlignmentLeft; // if([required isEqualToString:@"true"]) // { // [title appendString:@"*"]; // } NSString* value =@""; int count = [[cadedate_json valueForKey:@"count"] intValue]; for(int i=0;i=1) value=[value substringToIndex:value.length-1]; cell.labelTitle.text=title; if([required isEqualToString:@"true"]) { [cell.labelTitle sizeToFit]; CGRect frame =cell.labelTitle.frame; frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21); cell.starMark.frame = frame; cell.starMark.hidden=false; // [title appendString:@"*"]; // [title appendString:@"*"]; // NSString * htmlString = @" Some html string \n This is some text! "; } else { [cell.labelTitle sizeToFit]; cell.starMark.hidden=true; } cell.labelValue.text = value; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; if(self.cancommit==false && [required isEqualToString:@"true"] && (value==nil || value.length==0)) { CALayer *layer = [cell.contentView layer]; // layer.borderColor = [[UIColor redColor] CGColor]; // layer.borderWidth = 1.0; layer.shadowColor = [UIColor redColor].CGColor; layer.shadowOffset = CGSizeMake(0, 0); layer.shadowOpacity = 1; layer.shadowRadius = 2.0; } else { CALayer *layer = [cell.contentView layer]; // layer.borderColor = [[UIColor redColor] CGColor]; // layer.borderWidth = 1.0; layer.shadowColor = [UIColor clearColor].CGColor; layer.shadowOffset = CGSizeMake(0, 0); layer.shadowOpacity = 1; } cell.backgroundColor = [UIColor whiteColor]; return cell; } else if([control isEqualToString:@"model"]) { CommonEditorCellModel * cell= [tableView dequeueReusableCellWithIdentifier:@"CommonEditorCellModel" forIndexPath:indexPath]; int count = [[item_json valueForKey:@"count"] intValue]; NSDictionary * combine_json =[item_json objectForKey:@"combine"]; cell.bundle_item=combine_json; NSDictionary * master_json = [item_json objectForKey:@"combine_master"]; if (cell.masterBtn != nil) { if (master_json == nil) { cell.masterBtn.hidden = YES; } else{ cell.masterBtn.hidden = NO; cell.master_items = master_json; } } double dprice=0.0; if(cell.bundle_item!=nil) { int citem=0; int bcount=[[cell.bundle_item valueForKey:@"count"] intValue]; for(int bc=0;bc 0) { available_str = [NSString stringWithFormat:@"Available: %@",availability]; } else { // available_str = @"Available: In Production"; available_str = @"Available: Out of Stock"; } cell.avalibilityLabel.text = available_str; NSString* img_url = [item_json valueForKey:@"img_url"]; NSString* description = [item_json valueForKey:@"description"]; // NSString* identifier = [item_json valueForKey:@"identifier"]; // NSString* attribute = [item_json valueForKey:@"attribute"]; // NSString* total_price = [item_json valueForKey:@"total_price"] ; // NSString* unit_price = [item_json valueForKey:@"unit_price"] ; // NSString* mp = [item_json valueForKey:@"stockUom"]; double unitprice=[[item_json valueForKey:@"unit_price"] doubleValue]; int stockUom =[[item_json valueForKey:@"stockUom"] intValue]; double discount =[[item_json valueForKey:@"discount"] doubleValue]; NSString* discountstr=[NSString stringWithFormat:@"%@%% off", [RAUtils FloatFormat:discount]]; NSString* oldprice =[NSString stringWithFormat:@"%.2f",unitprice]; NSString* newunitprice=@""; if(dprice>0) newunitprice = [NSString stringWithFormat:@"%.2f+%.2f",unitprice* (1.0-discount/100),dprice]; else newunitprice = [NSString stringWithFormat:@"%.2f",unitprice* (1.0-discount/100)]; NSString* totalprice = [NSString stringWithFormat:@"%.2f",(unitprice* (1.0-discount/100)+dprice)*count]; BOOL can_see_price = [[RASingleton.sharedInstance globalParameterForKey:@"can_see_price"] boolValue]; BOOL price_hidden = [[RASingleton.sharedInstance globalParameterForKey:@"price_hidden"] boolValue]; if(can_see_price&&price_hidden==false) { } else { oldprice=nil; newunitprice=nil; totalprice=nil; } cell.labelDiscount.text = discountstr; cell.labelOldPrice.text = oldprice; cell.labelMasterPack.text =[NSString stringWithFormat:@"Sold in QTY of:%d", stockUom]; bool isfree = [[item_json valueForKey:@"is_free"]boolValue]; if(isfree) { cell.labelOldPrice.hidden = false; cell.labelOldPrice.textColor = [UIColor redColor]; cell.labelOldPrice.text=@"Free"; cell.labelOldPrice.hideline = true; cell.labelDiscount.hidden = true; } else { cell.labelOldPrice.textColor = [UIColor blackColor]; cell.labelOldPrice.hideline = false; if(discount==0) { cell.labelOldPrice.hidden = true; cell.labelDiscount.hidden = true; } else { cell.labelOldPrice.hidden = false; cell.labelDiscount.hidden = false; } } // if(discount==0) // { // cell.labelOldPrice.hidden = true; // cell.labelDiscount.hidden = true; // // } // else // { // cell.labelOldPrice.hidden = false; // cell.labelDiscount.hidden = false; // } // NSString* currency = [item_json valueForKey:@"currency"]; // int count =[[item_json valueForKey:@"count"] intValue]; cell.labelDescription.text = description; cell.labelCount.text = [NSString stringWithFormat:@"x %d",count]; // cell.labelID.text = identifier; // cell.labelSubtype.text = attribute; cell.labelTotalPrice.text= totalprice; // cell.labelUnitPrice.text=unit_price; cell.labelUnitPrice.text = newunitprice; cell.imgModel.image = [UIImage imageNamed:@"loading_s"]; cell.imgModel.contentMode = UIViewContentModeScaleAspectFit; NSString* file_name=[img_url lastPathComponent]; NSData* img_data=[FileCache load_cached_img:file_name loadFrom:img_url]; if(img_data!=nil) { UIImage * img =[UIImage imageWithData:img_data]; cell.imgModel.image = img; } else { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]]; dispatch_async(dispatch_get_main_queue(), ^{ if(downloadimg_data!=nil) { [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url]; UIImage * img =[UIImage imageWithData:downloadimg_data]; cell.imgModel.image = img; } else cell.imgModel.image = [UIImage imageNamed:@"notfound_s"]; }); }); } cell.backgroundColor = [UIColor whiteColor]; return cell; }else if([control isEqualToString:@"datepicker"]) { CellIdentifier = @"CommonEditorCellEnum"; CommonEditorCellEnum * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy]; NSString* value =[item_json valueForKey:@"value"]; // if([required isEqualToString:@"true"]) // { // [title appendString:@"*"]; // } cell.labelTitle.text=title; if([required isEqualToString:@"true"]) { [cell.labelTitle sizeToFit]; CGRect frame =cell.labelTitle.frame; frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21); cell.starMark.frame = frame; cell.starMark.hidden=false; // [title appendString:@"*"]; // [title appendString:@"*"]; // NSString * htmlString = @" Some html string \n This is some text! "; } else { [cell.labelTitle sizeToFit]; cell.starMark.hidden=true; } cell.labelValue.text = value; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; if(self.cancommit==false && [required isEqualToString:@"true"] && (value==nil || value.length==0)) { CALayer *layer = [cell.contentView layer]; // layer.borderColor = [[UIColor redColor] CGColor]; // layer.borderWidth = 1.0; layer.shadowColor = [UIColor redColor].CGColor; layer.shadowOffset = CGSizeMake(0, 0); layer.shadowOpacity = 1; layer.shadowRadius = 2.0; } else { CALayer *layer = [cell.contentView layer]; // layer.borderColor = [[UIColor redColor] CGColor]; // layer.borderWidth = 1.0; layer.shadowColor = [UIColor clearColor].CGColor; layer.shadowOffset = CGSizeMake(0, 0); layer.shadowOpacity = 1; } cell.backgroundColor = [UIColor whiteColor]; return cell; } else if([control isEqualToString:@"monthpicker"]) { CellIdentifier = @"CommonEditorCellEnum"; CommonEditorCellEnum * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy]; NSString* value =[item_json valueForKey:@"value"]; // if([required isEqualToString:@"true"]) // { // [title appendString:@"*"]; // } cell.labelTitle.text=title; if([required isEqualToString:@"true"]) { [cell.labelTitle sizeToFit]; CGRect frame =cell.labelTitle.frame; frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21); cell.starMark.frame = frame; cell.starMark.hidden=false; // [title appendString:@"*"]; // [title appendString:@"*"]; // NSString * htmlString = @" Some html string \n This is some text! "; } else { [cell.labelTitle sizeToFit]; cell.starMark.hidden=true; } cell.labelValue.text = value; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; if(self.cancommit==false && [required isEqualToString:@"true"] && (value==nil || value.length==0)) { CALayer *layer = [cell.contentView layer]; // layer.borderColor = [[UIColor redColor] CGColor]; // layer.borderWidth = 1.0; layer.shadowColor = [UIColor redColor].CGColor; layer.shadowOffset = CGSizeMake(0, 0); layer.shadowOpacity = 1; layer.shadowRadius = 2.0; } else { CALayer *layer = [cell.contentView layer]; // layer.borderColor = [[UIColor redColor] CGColor]; // layer.borderWidth = 1.0; layer.shadowColor = [UIColor clearColor].CGColor; layer.shadowOffset = CGSizeMake(0, 0); layer.shadowOpacity = 1; } cell.backgroundColor = [UIColor whiteColor]; return cell; } else if([control isEqualToString:@"signature"]) { CellIdentifier = @"CommonEditorCellSignature"; CommonEditorCellSignature * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; cell.imageviewSignature.contentMode = UIViewContentModeScaleAspectFit; NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy]; // if([required isEqualToString:@"true"]) // { // [title appendString:@"*"]; // } int disabble = [[item_json objectForKey:@"disable"] intValue]; if (disabble==1 || readonly) { cell.imageviewSignature.userInteractionEnabled = NO; } else { cell.imageviewSignature.userInteractionEnabled = YES; } cell.labelTitle.text = title; if([required isEqualToString:@"true"]) { [cell.labelTitle sizeToFit]; CGRect frame =cell.labelTitle.frame; frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21); cell.starMark.frame = frame; cell.starMark.hidden=false; // [title appendString:@"*"]; // [title appendString:@"*"]; // NSString * htmlString = @" Some html string \n This is some text! "; } else { [cell.labelTitle sizeToFit]; cell.starMark.hidden=true; } NSString* img_url = [item_json valueForKey:@"avalue"]; NSString* file_name=[img_url lastPathComponent]; NSData* img_data=[FileCache load_cached_img:file_name loadFrom:img_url]; if(img_data!=nil) { UIImage * img =[UIImage imageWithData:img_data]; cell.imageviewSignature.image=img ; } else { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]]; dispatch_async(dispatch_get_main_queue(), ^{ if(downloadimg_data!=nil) { [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url]; UIImage * img =[UIImage imageWithData:downloadimg_data]; cell.imageviewSignature.image=img ; } else cell.imageviewSignature.image=[UIImage imageNamed:@"taptosign_s"]; }); }); } cell.backgroundColor = [UIColor whiteColor]; return cell; // CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [self.editorTable cellForRowAtIndexPath:indexPath]; //cell.imageviewSignature.image = image; } else if ([control isEqualToString:@"range"]) { NSString *type = [item_json objectForKey:@"type"]; NSString *keyboard = [item_json objectForKey:@"keyboard"]; NSString *title = [item_json objectForKey:@"aname"]; NSString *min = [item_json objectForKey:@"min_value"]; NSString *max = [item_json objectForKey:@"max_value"]; CommonEditorRangeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CommonEditorRangeCell" forIndexPath:indexPath]; cell.indexPath = indexPath; cell.delegate = self; [cell setTitle:title]; [cell setMinValue:min maxValue:max]; if ([type isEqualToString:@"date"]) { [cell setType:CommonEditorRangeTypeDate]; } else { [cell setType:CommonEditorRangeTypeDefault]; } if([keyboard isEqualToString:@"number"]) { [cell setKeyboardType:UIKeyboardTypeDecimalPad]; } else { [cell setKeyboardType:UIKeyboardTypeDefault]; } return cell; } else if ([control isEqualToString:@"webview"]) { // CommonEditorWebCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CommonEditorWebCell" forIndexPath:indexPath]; CommonEditorWebCell * cell = [[NSBundle mainBundle] loadNibNamed:@"Phone_Web_Cell" owner:nil options:nil].firstObject; cell.webDelegate = self; NSString *html_str = [item_json objectForKey:@"value"]; // NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[html_str dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil]; // // cell.htmlLabel.attributedText = attrStr; // [cell.webview stopLoading]; [cell.webview loadHTMLString:html_str baseURL:nil]; // [cell.webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.baidu.com/"]]]; return cell; } else if ([control isEqualToString:@"banner"]) { CommonEditorBannerCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CommonEditorBannerCell" forIndexPath:indexPath]; // NSDictionary *item_json = @{ // @"control" : @"banner", // @"item_4": @{ // @"type" : @"image", // @"s": @"http://127.0.0.1/s2.jpg", // @"l": @"http://192.168.0.133:8080/site/u/NPD/20160615/108237-318N_7528.jpg" // }, // @"count": @(5), // @"item_2": @{ // @"type" : @"image", // @"s": @"http://127.0.0.1/s3.jpg", // @"l": @"http://192.168.0.133:8080/site/u/NPD/20160615/108237-318N_7526.jpg" // }, // @"item_3": @{ // @"type" : @"image", // @"s": @"http://127.0.0.1/s4.jpg", // @"l": @"http://192.168.0.133:8080/site/u/NPD/20160615/108237-318N_7527.jpg" // }, // @"item_0": @{ // @"type" : @"image", // @"s": @"http://127.0.0.1/s1.jpg", // @"l": @"http://192.168.0.133:8080/site/u/NPD/20160615/108237-318N_7524.jpg" // }, // @"item_1": @{ // @"type" : @"image", // @"s": @"http://127.0.0.1/s5.jpg", // @"l": @"http://192.168.0.133:8080/site/u/NPD/20160615/108237-318N_7525.jpg" // } // }; [cell setContent:item_json]; cell.delegate = self; return cell; } else { CellIdentifier = @"CommonEditorCellEdit"; UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; cell.backgroundColor = [UIColor whiteColor]; return cell; } } - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { // return [super tableview:tableView viewForHeaderInSection:section]; NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"]; if(value==nil) value=@""; unsigned long color = strtoul([value UTF8String],0,16); NSString* btntitle=nil ; NSString*labeltitle = nil; NSMutableDictionary* sectionjson= [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)section]] mutableCopy]; labeltitle= [sectionjson valueForKey:@"title"]; bool hide = [[sectionjson valueForKey:@"hide"]boolValue]; if(hide) { btntitle=@"Show"; // [section setValue:@"false" forKey:@"hide"]; // [sender setTitle:@"Show" forState:UIControlStateNormal]; } else{ btntitle=@"Hide"; } DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)]; // myView.backgroundColor = [UIColor whiteColor];//UIColorFromRGB(0x996633);; myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath; myView.layer.shadowColor = [UIColor blackColor].CGColor; myView.layer.shadowOffset = CGSizeMake(0, 0); myView.layer.shadowOpacity = 0.5; myView.layer.shadowRadius = 2.0; int linespace=0; if(section==0) linespace=11; UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0+linespace, 50, 33)]; btn.tag=section; // [btn setTitleColor:UIColorFromRGB(0x996633) forState:UIControlStateNormal]; [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside]; [btn setTitle:btntitle forState:UIControlStateNormal]; [myView addSubview:btn]; btn.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin; myView.autoresizingMask = UIViewAutoresizingFlexibleWidth; UILabel *titlelabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 5.5+linespace, 200, 20)]; titlelabel.textColor=UIColorFromRGB(color);//[UIColor whiteColor]; titlelabel.backgroundColor = [UIColor clearColor]; titlelabel.text=NSLocalizedString(labeltitle, nil); titlelabel.font = [UIFont boldSystemFontOfSize:20]; [titlelabel sizeToFit]; [myView addSubview:titlelabel]; // // UILabel *contactlabel = [[UILabel alloc] initWithFrame:CGRectMake(300, 0, 90, 22)]; // contactlabel.textColor=[UIColor whiteColor]; // contactlabel.backgroundColor = [UIColor clearColor]; // contactlabel.text=NSLocalizedString(@"Contact", nil); // [contactlabel sizeToFit]; // [myView addSubview:contactlabel]; // // // UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(400, 0, 90, 22)]; // modellabel.textColor=[UIColor whiteColor]; // modellabel.backgroundColor = [UIColor clearColor]; // modellabel.text=NSLocalizedString(@"Model", nil); // [modellabel sizeToFit]; // [myView addSubview:modellabel]; // // UILabel *pricelabel = [[UILabel alloc] initWithFrame:CGRectMake(500, 0, 90, 22)]; // pricelabel.textColor=[UIColor whiteColor]; // pricelabel.backgroundColor = [UIColor clearColor]; // pricelabel.text=NSLocalizedString(@"Price", nil); // [pricelabel sizeToFit]; // [myView addSubview:pricelabel]; // // // // UILabel *timelabel = [[UILabel alloc] initWithFrame:CGRectMake(630, 0, 90, 22)]; // timelabel.textColor=[UIColor whiteColor]; // timelabel.backgroundColor = [UIColor clearColor]; // timelabel.text=NSLocalizedString(@"Create time", nil); // [timelabel sizeToFit]; // [myView addSubview:timelabel]; // // // // UILabel *statuslabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, 60, 22)]; // statuslabel.textColor=[UIColor whiteColor]; // statuslabel.backgroundColor = [UIColor clearColor]; // statuslabel.text=NSLocalizedString(@"Status", nil); // [statuslabel sizeToFit]; // [myView addSubview:statuslabel]; // myView.backgroundColor = UIColor.lightGrayColor; UIColor * c=myView.backgroundColor; return myView; } // -(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row]; bool readonly = [[self.content_data_download valueForKey:@"readonly"]boolValue]; int disable = [[item_json valueForKey:@"disable"] intValue]; DebugLog(@"tableView willSelectRowAtIndexPath"); // NSString* control = [item_json valueForKey:@"control"]; if([control isEqualToString:@"enum"])//||[control isEqualToString:@"ui"]) { // int disable = [[item_json valueForKey:@"disable"] intValue]; if(disable==1||readonly) return nil; // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",indexPath.row]]; NSDictionary* cadedate_json = [item_json objectForKey:@"cadedate"]; // NSDictionary* value_json = [item_json objectForKey:@"value"]; NSString* single_select = [item_json valueForKey:@"single_select"]; // NSString* required =[item_json valueForKey:@"required"]; NSString* title = [item_json valueForKey:@"aname"]; BOOL sort = [[item_json objectForKey:@"sort"] boolValue]; if (sort) { EnumSelectAndSortViewController *vc = [[UIStoryboard storyboardWithName:@"EnumSelectAndSort" bundle:nil] instantiateViewControllerWithIdentifier:@"EnumSelectAndSortViewController"]; vc.title = title; [vc setEnumDataSource:cadedate_json]; vc.indexPath = indexPath; __weak typeof(self) weakSelf = self; vc.returnBlock = ^(NSDictionary *returnValue, NSIndexPath *idxPath) { [weakSelf EnumValueChanged:[returnValue mutableCopy] indexPath:idxPath]; }; [self.navigationController pushViewController:vc animated:YES]; return nil; } BOOL online = [[item_json objectForKey:@"online"] boolValue]; if (online) { int max_select = [[item_json valueForKey:@"max"] intValue]; EnumSelectOnlineViewController* enumvc =[[UIStoryboard storyboardWithName:@"CommonEditor" bundle:nil] instantiateViewControllerWithIdentifier:@"EnumSelectOnlineViewController"]; enumvc.delegate = self; enumvc.max_select = max_select; enumvc.updatePosition = indexPath; enumvc.online_params = item_json[@"params"]; // if([[required lowercaseString] isEqualToString:@"true"]) // enumvc.canbeEmpty = false; // else // enumvc.canbeEmpty =true; // enumvc.cadedate = [cadedate_json mutableCopy]; enumvc.title = title; // enumvc.value = [value_json mutableCopy]; enumvc.single_select =[[single_select lowercaseString] isEqualToString:@"true"]; [self.navigationController pushViewController:enumvc animated:true]; return nil; } int max_select = [[item_json valueForKey:@"max"] intValue]; EnumSelectViewController* enumvc =[[UIStoryboard storyboardWithName:@"CommonEditor" bundle:nil] instantiateViewControllerWithIdentifier:@"EnumSelectorViewController"]; enumvc.delegate = self; enumvc.max_select = max_select; enumvc.updatePosition = indexPath; // if([[required lowercaseString] isEqualToString:@"true"]) // enumvc.canbeEmpty = false; // else // enumvc.canbeEmpty =true; enumvc.cadedate = [cadedate_json mutableCopy]; enumvc.title = title; // enumvc.value = [value_json mutableCopy]; enumvc.single_select =[[single_select lowercaseString] isEqualToString:@"true"]; [self.navigationController pushViewController:enumvc animated:true]; } else if([control isEqualToString:@"editor"]) { [self handle_editor_cell_select:tableView IndexPath:indexPath]; } else if([control isEqualToString:@"action"]) { if (disable || readonly) { return nil; } NSString* value = [item_json valueForKey:@"value"]; [self commonAction:value index:indexPath data:[item_json mutableCopy]]; } else if([control isEqualToString:@"datepicker"]) { if (disable || readonly) { return nil; } // NSString* title = [item_json valueForKey:@"aname"]; NSString* value =[item_json valueForKey:@"value"]; NSString* type =[item_json valueForKey:@"type"]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; DatePickerViewController* dpvc =[ [UIStoryboard storyboardWithName:@"CommonEditor" bundle:nil] instantiateViewControllerWithIdentifier:@"DatePickerViewController"]; if([[type lowercaseString] isEqualToString:@"date"]) { dpvc.pickerMode = UIDatePickerModeDate; [dateFormatter setDateFormat:@"MM/dd/yyyy"]; } else if([[type lowercaseString] isEqualToString:@"time"]) { dpvc.pickerMode = UIDatePickerModeTime; [dateFormatter setDateFormat:@"HH:mm:ss"]; } else { dpvc.pickerMode = UIDatePickerModeDateAndTime; [dateFormatter setDateFormat:@"MM/dd/yyyy HH:mm:ss"]; } __weak typeof(self) weakSelf = self; NSDate *date = [dateFormatter dateFromString:value]; dpvc.date = date; dpvc.formatter = dateFormatter; dpvc.labelTime.text = value; dpvc.blk_Set=^(NSString *date) { [weakSelf DateTimeValueChanged:date indexPath:indexPath]; }; [self.navigationController pushViewController:dpvc animated:true]; }else if([control isEqualToString:@"monthpicker"]) { if (disable || readonly) { return nil; } // NSString* title = [item_json valueForKey:@"aname"]; NSString* value =[item_json valueForKey:@"value"]; if (value==nil || value.length==0) { value=@"1/2015"; } // NSString* type =[item_json valueForKey:@"type"]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; MonthPickerViewController* mpvc =[[UIStoryboard storyboardWithName:@"CommonEditor" bundle:nil] instantiateViewControllerWithIdentifier:@"MonthPickerViewController"]; // if([[type lowercaseString] isEqualToString:@"date"]) // { // dpvc.pickerMode = UIDatePickerModeDate; [dateFormatter setDateFormat:@"MM/yyyy"]; NSDate *date = [dateFormatter dateFromString:value]; mpvc.current_date =date; mpvc.updatePosition = indexPath; mpvc.delegate = self; // } // else if([[type lowercaseString] isEqualToString:@"time"]) // { // dpvc.pickerMode = UIDatePickerModeTime; // [dateFormatter setDateFormat:@"HH:mm:ss"]; // } // else // { // dpvc.pickerMode = UIDatePickerModeDateAndTime; // [dateFormatter setDateFormat:@"yyyy/MM/dd HH:mm:ss"]; // } // NSDate *date = [dateFormatter dateFromString:value]; // dpvc.date = date; // dpvc.formatter = dateFormatter; // dpvc.labelTime.text = value; [self.navigationController pushViewController:mpvc animated:true]; } else if([control isEqualToString:@"signature"]) { // SignatureViewController * signvc =[ [UIStoryboard storyboardWithName:@"signature" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SignatureViewController"]; // signvc.title = [item_json valueForKey:@"aname"]; // signvc.indexPath = indexPath; // // signvc.delegate = self; // CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [self.editorTable cellForRowAtIndexPath:indexPath]; // // signvc.existSignature = cell.imageviewSignature.image ; // // // // [self.navigationController pushViewController:signvc animated:true]; if (disable || readonly) { return nil; } __block UIImage* signimg=nil; SignatureViewController * vc =[ [UIStoryboard storyboardWithName:@"signature" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SignatureViewController"]; __weak typeof(self) weakself = self; vc.onReturnImg = ^(UIImage* img) { signimg = img; if(signimg!=nil) { #ifdef OFFLINE_MODE AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; BOOL offline_mode = [[appDelegate globalParameterForKey:@"offline_mode"] boolValue]; if(offline_mode) { NSData *data = [OLDataProvider offline_saveBusinesscard:UIImagePNGRepresentation(img)]; // 再将NSData转为字符串 NSString *jsonStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; // NSMutableString *str = [[NSMutableString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]; DebugLog(@"data string: %@",jsonStr); NSError *error=nil; NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error]; //NSMutableArray* arr_ret = [[NSMutableArray alloc] init]; if([[json valueForKey:@"result"] intValue]==2) { NSString* img_url_down = json[@"img_url_aname"]; // if(img_url_down.length==0) // img_url_down=@""; NSString* img_url_up = json[@"img_url"]; // if(img_url_up.length==0) // img_url_up=@""; NSMutableDictionary* item_json =((NSMutableArray*)weakself.content_data_control[indexPath.section])[indexPath.row]; [item_json setValue:img_url_down forKey:@"avalue"]; [item_json setValue:img_url_up forKey:@"value"]; [item_json setValue:@"true" forKey:@"dirty"]; NSMutableDictionary* section_json = [[weakself.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy]; [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]]; [weakself.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]]; weakself.content_data_control = [weakself translate_json:weakself.content_data_download changed:weakself.changed_data]; CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [weakself.editorTable cellForRowAtIndexPath:indexPath]; cell.imageviewSignature.image = signimg; } else { [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Upload Image" controller:weakself] ; } } else #endif { NSData *imageData = UIImagePNGRepresentation(img); NSMutableDictionary* params = [[NSMutableDictionary alloc] init]; AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; NSString *user = [RASingleton.sharedInstance globalParameterForKey:@"user"]; NSString *password = [RASingleton.sharedInstance globalParameterForKey:@"password"]; if(user!=nil) [params setValue:user forKey:@"user"]; if(password!=nil) [params setValue:password forKey:@"password"]; __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Upload Signature" completion:^{ [NetworkUtils upload:imageData FileName:@"test.jpg" Params:params ToHost:URL_UPLOAD_IMG Result:^(NSMutableDictionary *json) { // dispatch_async(dispatch_get_main_queue(), ^{ [waitalert dismissViewControllerAnimated:YES completion:^{ if([[json valueForKey:@"result"] intValue]==2) { NSString* img_url_down = json[@"img_url_aname"]; NSString* img_url_up = json[@"img_url"]; NSMutableDictionary* item_json =((NSMutableArray*)weakself.content_data_control[indexPath.section])[indexPath.row]; [item_json setValue:img_url_down forKey:@"avalue"]; [item_json setValue:img_url_up forKey:@"value"]; [item_json setValue:@"true" forKey:@"dirty"]; NSMutableDictionary* section_json = [[weakself.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy]; [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]]; [weakself.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]]; weakself.content_data_control = [weakself translate_json:weakself.content_data_download changed:weakself.changed_data]; CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [weakself.editorTable cellForRowAtIndexPath:indexPath]; cell.imageviewSignature.image = signimg; } else if([[json valueForKey:@"result"] intValue]==RESULT_LOGIN_ON_OTHER_DEVICE) { [[NSNotificationCenter defaultCenter] postNotificationName:RA_NOTIFICATION_KICKOUT object:nil]; } else { [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Upload Image" controller:weakself] ; } }]; // }); } Progress:nil DecryptHandler:nil]; }]; self.alert = waitalert; // AFHTTPRequestSerializer* serializer=[AFHTTPRequestSerializer serializer] ; // // NSMutableURLRequest *request = [serializer multipartFormRequestWithMethod:@"POST" URLString:URL_UPLOAD_IMG parameters:params constructingBodyWithBlock:^(id formData) { // [formData appendPartWithFileData:imageData name:@"upfile" fileName:@"test.jpg" mimeType:@"image/png"]; // } error:nil]; // // // // AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]; // // // // // NSProgress *progress = nil; // UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Upload Signature"]; // NSURLSessionUploadTask *uploadTask = [manager uploadTaskWithStreamedRequest:request progress:&progress completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) { // // // [progress removeObserver:self forKeyPath:@"fractionCompleted"]; // // // [waitalert dismissViewControllerAnimated:YES completion:nil]; // // if (error) { // // NSString* err_msg = [error localizedDescription]; // DebugLog(@"%@",err_msg);// [self.view updateWithMessage:[NSString stringWithFormat:@"Error : %@!", error.debugDescription]]; // // // NSMutableString *str = [[NSMutableString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]; // // DebugLog(@"data string: %@",str); // // [RAUtils message_alert:@"Can not connect to server please try again." title:@"Upload Image" controller:weakself] ; // // } else { // DebugLog(@"response "); // // // // NSData *data = [NSJSONSerialization dataWithJSONObject:(NSDictionary*)responseObject options:kNilOptions error:nil]; // // // 再将NSData转为字符串 // NSString *jsonStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; // // // NSMutableString *str = [[NSMutableString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]; // // DebugLog(@"data string: %@",jsonStr); // // NSDictionary* json = responseObject; // // // //NSMutableArray* arr_ret = [[NSMutableArray alloc] init]; // if([[json valueForKey:@"result"] intValue]==2) // { // NSString* img_url_down = json[@"img_url_aname"]; // // if(img_url_down.length==0) // // img_url_down=@""; // NSString* img_url_up = json[@"img_url"]; // // if(img_url_up.length==0) // // img_url_up=@""; // // NSMutableDictionary* item_json =((NSMutableArray*)weakself.content_data_control[indexPath.section])[indexPath.row]; // // [item_json setValue:img_url_down forKey:@"avalue"]; // [item_json setValue:img_url_up forKey:@"value"]; // [item_json setValue:@"true" forKey:@"dirty"]; // NSMutableDictionary* section_json = [[weakself.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy]; // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",indexPath.row]]; // // [weakself.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]]; // weakself.content_data_control = [weakself translate_json:weakself.content_data_download changed:weakself.changed_data]; // // // CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [weakself.editorTable cellForRowAtIndexPath:indexPath]; // // cell.imageviewSignature.image = signimg; // // // } // else // { // [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Upload Image" controller:weakself] ; // } // // // // // // // } // // // }]; // // [uploadTask resume]; } } }; [self.navigationController pushViewController:vc animated:NO]; } // else if([control isEqualToString:@"action "]) // { // // DebugLog(@"action push"); // // SignatureViewController * signvc =[ [UIStoryboard storyboardWithName:@"signature" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SignatureViewController"]; // // signvc.title = [item_json valueForKey:@"aname"]; // // signvc.indexPath = indexPath; // // signvc.delegate = self; // // CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [self.editorTable cellForRowAtIndexPath:indexPath]; // // // // signvc.existSignature = cell.imageviewSignature.image ; // // // // // // // // [self.navigationController pushViewController:signvc animated:true]; // } return nil; } //- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath //{ // // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",indexPath.row]]; // // NSString* orderid = [item_json valueForKey:@"id"]; // // // if (self.delegate && [self.delegate respondsToSelector:@selector(SelectOrder:)]) { // // [self.delegate SelectOrder:orderid]; // // } // // // // [self dismissViewControllerAnimated:YES // // completion:^{ // // //一定要移除手势 否则下次 没有子视图的时候 点击 会崩溃拉 // // AppDelegate *app = [[UIApplication sharedApplication] delegate]; // // [app.window removeGestureRecognizer:self.tapGesture]; // // }]; // // [pvc categoryMenuSelected:indexPath.row]; //} #pragma mark monthpicker ViewControllerDelegate -(void) MPValueChanged:(NSString *)value indexPath :(NSIndexPath*) indexPath { CommonEditorCellEnum * cell= (CommonEditorCellEnum*) [self.editorTable cellForRowAtIndexPath:indexPath]; cell.labelValue.text = value; { CALayer *layer = [cell.contentView layer]; // layer.borderColor = [[UIColor redColor] CGColor]; // layer.borderWidth = 1.0; layer.shadowColor = [UIColor clearColor].CGColor; layer.shadowOffset = CGSizeMake(0, 0); layer.shadowOpacity = 1; layer.shadowRadius = 2.0; } // NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy]; // UITableViewCell *cell = (UITableViewCell *) paramSender.superview.superview; // NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell]; NSMutableDictionary* section_json=nil; // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row); NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy]; // NSString* check=@"false"; // if([paramSender isOn]) // check=@"true"; // [item_json setValue:value forKey:@"dirty"]; NSString* subid=[item_json valueForKey:@"subid"]; [item_json setValue:value forKey:@"value"]; if(subid==nil) { section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy]; int count=0; count=[[section_json valueForKey:@"count"] intValue]; for(int i=0;itextField.text.length ||[string isEqualToString:@""]); } } NSCharacterSet *cs; if([keyboard isEqualToString:@"number"]) cs = [[NSCharacterSet characterSetWithCharactersInString:NUMBERS]invertedSet]; else cs = [[NSCharacterSet characterSetWithCharactersInString:INTNUMBERS]invertedSet]; NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs]componentsJoinedByString:@""]; BOOL canChange = [string isEqualToString:filtered]; if(lenth==0) return canChange; else { return canChange&& (lenth>textField.text.length ||[string isEqualToString:@""]); } } - (void)textFieldDidEndEditing:(UITextField *)textField { DebugLog(@"textFieldDidEndEditing"); // UITableViewCell *cell = (UITableViewCell *) textField.superview.superview; NSIndexPath * indexPath = self.lastedit_from; NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row]; if ([item_json objectForKey:@"fill"]) { NSString *fillText = [item_json objectForKey:@"fill"]; if (fillText && textField.text.length == 0) { textField.text = fillText; } } [self textfieldSetValue:indexPath value:textField.text]; // NSMutableDictionary* section_json=nil; // // // // textField.text = [textField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; // // // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row); // NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy]; // // NSString* subid=[item_json valueForKey:@"subid"]; // NSString* refresh_trigger = [item_json valueForKey:@"name"]; // // [item_json setValue:@"true" forKey:@"dirty"]; // [item_json setValue:textField.text forKey:@"value"]; // if([[item_json valueForKey:@"keyboard"] isEqualToString:@"number"]) // { // float f = [ textField.text floatValue]; // [item_json setValue:[NSString stringWithFormat:@"%.2f",f] forKey:@"value"]; // // } // // // [self.content_data_control[indexPath.section] setObject:item_json forKey:indexPath.row]; // if(subid==nil) // { // section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy]; // int count=0; // // count=[[section_json valueForKey:@"count"] intValue]; // // for(int i=0;i0) [modify_item setValue:valuestr forKey:@"value"]; else [modify_item setValue:@"" forKey:@"value"]; [modify_item setValue:@"true" forKey:@"dirty"]; [subjson setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",l ]]; } } [boolitem setObject:subjson forKey:@"sub_item"]; if([value isEqualToString:@"true"]) [switch_item setObject:boolitem forKey:@"true"]; else [switch_item setObject:boolitem forKey:@"false"]; } return switch_item; } -(NSMutableDictionary*) fill_enum_subitem:(NSMutableDictionary *) enum_item subid:(NSArray*) subid source:(NSMutableDictionary*)source mapping:(NSDictionary*)mapping //step:(int) step { NSMutableDictionary* cadedatejson = [[enum_item objectForKey:@"cadedate"] mutableCopy]; int count = [[cadedatejson valueForKey:@"count"]intValue]; for(int i=0;i0) [modify_item setValue:valuestr forKey:@"value"]; else [modify_item setValue:@"" forKey:@"value"]; //[modify_item setValue:valuestr forKey:@"value"]; // [modify_item setValue:@"true" forKey:@"dirty"]; } } [modify_item setValue:@"true" forKey:@"dirty"]; [subjson setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",l ]]; // [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",item ]]; // NSMutableDictionary* modify_item= [[section_json objectForKey:[NSString stringWithFormat:@"item_%d",ic ]] mutableCopy]; } [val_json setObject:subjson forKey:@"sub_item"]; } } [cadedatejson setObject:val_json forKey:[NSString stringWithFormat:@"val_%d",i]]; } [enum_item setObject:cadedatejson forKey:@"cadedate"]; return enum_item; } -(NSMutableDictionary*) switch_subitem_changed:(NSMutableDictionary *) switch_item subid:(NSArray*) subid value:(NSMutableDictionary*)valuejson step:(int) step { int index = [(NSString*)subid[step] intValue]; NSString* value = [switch_item valueForKey:@"value"]; NSMutableDictionary* boolitem=nil; NSMutableDictionary* subjson=nil; if([value isEqualToString:@"true"]) { boolitem =[[switch_item objectForKey:@"true"] mutableCopy]; } else { boolitem =[[switch_item objectForKey:@"false"] mutableCopy]; } subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy]; if(subjson!=nil) { NSMutableDictionary * itemjson=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",index]] mutableCopy]; if(step==subid.count-1) { itemjson =valuejson; } [subjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",index]]; [boolitem setObject:subjson forKey:@"sub_item"]; if([value isEqualToString:@"true"]) [switch_item setObject:boolitem forKey:@"true"]; else [switch_item setObject:boolitem forKey:@"false"]; return switch_item; } return nil; } #pragma mark Request Editor //-(NSDictionary*)request_Editor:(NSString*) request_url params:(NSMutableDictionary*)params //{ // return [RANetwork request_Editor:request_url params:params]; //} // //- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath //{ // // NSLog(@"willDisplayCell"); // NSString *cellclass; // const char *class_name_ch = object_getClassName([cell class]); // cellclass = [NSString stringWithUTF8String:class_name_ch]; // // CommonEditorCellTextView * tvcell=nil; // if([cellclass isEqualToString:@"CommonEditorCellTextView"]) // { // tvcell=(CommonEditorCellTextView*)self.editingcell; // tvcell.textview.scrollEnabled=true; // // // } //} //- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath*)indexPath //{ // // NSLog(@"didEndDisplayingCell"); // NSString *cellclass; // const char *class_name_ch = object_getClassName([cell class]); // cellclass = [NSString stringWithUTF8String:class_name_ch]; // // CommonEditorCellTextView * tvcell=nil; // if([cellclass isEqualToString:@"CommonEditorCellTextView"]) // { // tvcell=(CommonEditorCellTextView*)self.editingcell; // tvcell.textview.scrollEnabled=false; // // // } // //} #pragma mark - Responding to keyboard events - (void)keyboardWillChangeFrame:(NSNotification *)notification { // return; DebugLog(@"keyboardWillChangeFrame"); // 使用tableContainer计算frame 保证屏幕旋转后table height正确 CGRect table_origin_screen_frame = [self.tableContainer convertRect:self.tableContainer.bounds toView:self.view.window]; // NSTimeInterval duration = [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]; // duration *= 0.0; CGRect end = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; CGFloat end_y = end.origin.y; CGRect screenframe=[[UIScreen mainScreen] bounds]; self.autocompleteView.frame= CGRectMake(screenframe.origin.x, screenframe.origin.y, screenframe.size.width, end_y); NSIndexPath *indexPath = [self.editorTable indexPathForCell:self.editingcell]; CGRect table_frame = self.editorTable.frame; // table底部距离键盘顶部偏移 CGFloat offset = CGRectGetMaxY(table_origin_screen_frame) - end_y; if (offset > 0) { // table -> top > offset: table.y = -offset // 事实上top:topLayoutGuide // self.additionalSafeAreaInsets float y0=self.view.safeAreaLayoutGuide.topAnchor.accessibilityActivationPoint.y; CGFloat topAvailableHeight = (CGRectGetMinY(table_origin_screen_frame) - y0); if (topAvailableHeight > 0 || true) { if (topAvailableHeight > offset) { table_frame.origin.y = -offset; } else { // 向上移动到topLayoutGuide,不足部分通过缩减高度到达keyboard顶部 // table_frame.origin.y = -topAvailableHeight; // table_frame.size.height = (end_y - self.topLayoutGuide.length); for (NSLayoutConstraint *constraint in self.tableContainer.constraints) { if (constraint.firstAttribute == NSLayoutAttributeBottom) { // int a=0; [self.tableContainer removeConstraint:constraint]; NSLayoutConstraint *bottom_constraint = [NSLayoutConstraint constraintWithItem:self.editorTable attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.tableContainer attribute:NSLayoutAttributeBottom multiplier:1 constant:-end.size.height]; self.tb_bottom_constraint = bottom_constraint; [self.tableContainer addConstraint:bottom_constraint]; break; // } } } } else { // contentInset = (top = 64, left = 0, bottom = 0, right = 0),topAvailableHeight = -64 table_frame.size.height = table_origin_screen_frame.size.height - offset; } // table_frame.size.height = CGRectGetHeight(table_origin_screen_frame) - (CGRectGetMaxY(table_origin_screen_frame) - end_y); } else { // table_frame.size.height = CGRectGetHeight(table_origin_screen_frame); // table_frame = self.tableContainer.bounds; for (NSLayoutConstraint *constraint in self.tableContainer.constraints) { if (constraint.firstAttribute == NSLayoutAttributeBottom) { // int a=0; [self.tableContainer removeConstraint:constraint]; NSLayoutConstraint *bottom_constraint = [NSLayoutConstraint constraintWithItem:self.editorTable attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.tableContainer attribute:NSLayoutAttributeBottom multiplier:1 constant:0]; self.tb_bottom_constraint = bottom_constraint; [self.tableContainer addConstraint:bottom_constraint]; break; // } } } self.editorTable.frame = table_frame; CGRect cell_screen_frame = [self.editingcell convertRect:self.editingcell.bounds toView:self.view.window]; int cover =CGRectGetMaxY(cell_screen_frame) - end_y; if (cover>0) { // Cell 被键盘遮挡后才滚动 NSLog(@"scrollToRowAtIndexPath"); NSString *cellclass; const char *class_name_ch = object_getClassName([self.editingcell class]); cellclass = [NSString stringWithUTF8String:class_name_ch]; CommonEditorCellTextView * tvcell=nil; // if([cellclass isEqualToString:@"CommonEditorCellTextView"]) { // tvcell=(CommonEditorCellTextView*)self.editingcell; // tvcell.textview.scrollEnabled=false; CGPoint current_offset=self.editorTable.contentOffset; NSLog(@"OFFSET %f",current_offset.y); CGPoint moveto= CGPointMake(self.editingcell.frame.origin.x,current_offset.y+cover); [self.editorTable setContentOffset:moveto]; } ; // self.editorTable cell // self.editorTable scrollto // self.editorTable scrollToNearestSelectedRowAtScrollPosition:(UITableViewScrollPosition) animated:<#(BOOL)#> // CGPoint current_offset=self.editorTable.contentOffset; // // NSLog(@"OFFSET %f",current_offset.y); // CGPoint moveto= CGPointMake(self.editingcell.frame.origin.x,current_offset.y+cover); // [self.editorTable setContentOffset:self.editingcell.frame.origin]; // [self.editorTable scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionNone animated:NO]; // } // =============================================== if (end_y >= [UIScreen mainScreen].bounds.size.height) { self.keyboard_show = NO; } else { self.keyboard_show = YES; } } - (void)keyboardDidChangeFrame:(NSNotification *)notification { NSLog(@"keyboardDidChangeFrame"); // NSString *cellclass; // const char *class_name_ch = object_getClassName([self.editingcell class]); // cellclass = [NSString stringWithUTF8String:class_name_ch]; // // CommonEditorCellTextView * tvcell=nil; // if([cellclass isEqualToString:@"CommonEditorCellTextView"]) // { // // tvcell=(CommonEditorCellTextView*)self.editingcell; // tvcell.textview.scrollEnabled=true; // // // } return; // 使用tableContainer计算frame 保证屏幕旋转后table height正确 // CGRect table_origin_screen_frame = [self.tableContainer convertRect:self.tableContainer.bounds toView:self.view.window]; CGRect screen_rect = [RAUtils relativeFrameForScreenWithView:self.editorTable]; // // // NSTimeInterval duration = [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]; // // duration *= 0.0; CGRect end = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; // CGRect begin = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue]; float kbheight = end.size.height; CGFloat keyboard_top = end.origin.y; NSLog(@"keyboard rect: %@",NSStringFromCGRect(end)); NSLog(@"view rect: %@",NSStringFromCGRect(self.view.frame)); NSLog(@"view screen rect: %@",NSStringFromCGRect(screen_rect)); // self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height); float dark = screen_rect.origin.y+screen_rect.size.height-keyboard_top; if(dark>0) { // self.editorTable.scrollEnabled = true; // self.editorTable.contentSize = CGSizeMake(self.editorTable.frame.size.width, self.editorTable.frame.size.height+dark); self.editorTable.contentSize=CGSizeMake(self.editorTable.contentSize.width, self.editorTable.contentSize.height+kbheight); } else { // self.editorTable.scrollEnabled = false; // self.editorTable.contentSize = self.editorTable.frame.size; self.editorTable.contentSize=CGSizeMake(self.editorTable.contentSize.width, self.editorTable.contentSize.height-kbheight); } } //static float table_origin_h = 0; // //- (void)keyboardWillShow:(NSNotification *)notification { // DebugLog(@"keyboardWillShow"); //// //// if(self.keyboard_show) //// return; //// //// self.keyboard_show=true; //// /* //// Reduce the size of the text view so that it's not obscured by the keyboard. //// Animate the resize so that it's in sync with the appearance of the keyboard. //// */ //// //// NSDictionary *userInfo = [notification userInfo]; //// //// // Get the origin of the keyboard when it's displayed. //// NSValue* aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey]; //// //// // Get the top of the keyboard as the y coordinate of its origin in self's view's coordinate system. The bottom of the text view's frame should align with the top of the keyboard's final position. //// // CGRect keyboardRect = [aValue CGRectValue]; //// CGSize keyboardSize = [aValue CGRectValue].size; //// DebugLog(@"keyboard height:%f",keyboardSize.height); //// // Get the duration of the animation. //// NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey]; //// NSTimeInterval animationDuration; //// [animationDurationValue getValue:&animationDuration]; //// //// //// // if(self.keyboard_h==0) //// // { //// self.keyboard_h =keyboardSize.height; //// CGRect cellrect_screen = [RAUtils relativeFrameForScreenWithView:self.editingcell]; //// CGRect rect_screen = [ UIScreen mainScreen ].bounds; //// //// // int vpos =self.view.frame.origin.y+self.view.frame.size.height; //// // int loginpos = self.editingcell.frame.origin.y+self.editingcell.frame.size.height; //// // //// int cellpos = cellrect_screen.origin.y+cellrect_screen.size.height; //// // screen.size.height-keyboardSize.height-(cellpos_screen.origin.x+cellpos_screen.size.height); //// self.ioffset = cellpos-(rect_screen.size.height-keyboardSize.height);//rect_screen.size.height-keyboardSize.height-(rect_screen.origin.y+rect_screen.size.height);//keyboardSize.height -(self.view.frame.size.height-loginpos); //// if(self.ioffset>0) //// { //// // self.resize = true; //// //// //// CGPoint contentOffsetPoint = self.editorTable.contentOffset; //// //// //// contentOffsetPoint.y+=self.ioffset; //// //// self.editorTable.contentOffset=contentOffsetPoint; //// //// //// // NSTimeInterval animationDuration = 0.30f; //// // CGRect frame = self.view.frame; //// // frame.origin.y -=self.ioffset;//view的Y轴上移 //// // frame.size.height +=self.ioffset; //View的高度增加 //// // self.view.frame = frame; //// // [UIView beginAnimations:@"ResizeView" context:nil]; //// // [UIView setAnimationDuration:animationDuration]; //// // self.view.frame = frame; //// // [UIView commitAnimations];//设置调整界面的动画效果 //// } //// //// table_origin_h = self.editorTable.frame.size.height; //// self.editorTable.frame = CGRectMake(0, 0, self.editorTable.frame.size.width, self.editorTable.frame.size.height-self.keyboard_h); //// //// // CGSize tablecontent =self.editorTable.contentSize; //// // tablecontent.height=tablecontent.height+self.keyboard_h; //// // self.editorTable.contentSize=tablecontent; //// // } //// // Animate the resize of the text view's frame in sync with the keyboard's appearance. //// // [self moveInputBarWithKeyboardHeight:keyboardRect.size.height withDuration:animationDuration]; //} //- (void)keyboardWillHide:(NSNotification *)notification { // DebugLog(@"keyboardWillHide"); // //// self.keyboard_show=false; //// NSDictionary* userInfo = [notification userInfo]; //// //// /* //// Restore the size of the text view (fill self's view). //// Animate the resize so that it's in sync with the disappearance of the keyboard. //// */ //// NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey]; //// NSTimeInterval animationDuration; //// [animationDurationValue getValue:&animationDuration]; //// CGSize tablecontent =self.editorTable.contentSize; //// tablecontent.height=tablecontent.height-self.keyboard_h; //// // self.editorTable.contentSize=tablecontent; //// //// self.editorTable.frame = CGRectMake(0, 0, self.editorTable.frame.size.width, table_origin_h); //// //// self.keyboard_h= 0; //// DebugLog(@"before refresh %@",NSStringFromCGSize(self.editorTable.contentSize)); //// //// //// // if(self.resize) //// // { //// // NSTimeInterval animationDuration = 0.30f; //// // CGRect frame = self.view.frame; //// // // if(prewTag == textField.tag) //当结束编辑的View的TAG是上次的就移动 //// // // { //还原界面 //// // // moveY = prewMoveY; //// // frame.origin.y +=self.ioffset; //// // frame.size. height -=self.ioffset; //// // self.view.frame = frame; //// // // } //// // //self.view移回原位置 //// // [UIView beginAnimations:@"ResizeView" context:nil]; //// // [UIView setAnimationDuration:animationDuration]; //// // self.view.frame = frame; //// // [UIView commitAnimations]; //// // //[textField resignFirstResponder]; //// // self.ioffset=0; //// // } //// //// //// // [self moveInputBarWithKeyboardHeight:0.0 withDuration:animationDuration]; //} #pragma mark - RageCell Delegate - (void)commonEditorRangeCell:(CommonEditorRangeCell *)cell didChangeMinValue:(NSString *)minValue maxValue:(NSString *)maxValue atIndexPath:(NSIndexPath *)indexPath{ if (indexPath == nil) { if (cell != nil) { indexPath = [self.editorTable indexPathForCell:cell]; } else { return; } } if (indexPath == nil) { return; } NSString *section_key = [NSString stringWithFormat:@"section_%ld",indexPath.section]; NSString *item_key = [NSString stringWithFormat:@"item_%ld",indexPath.row]; NSMutableDictionary *section_json = [[self.content_data_download objectForKey:section_key] mutableCopy]; NSMutableDictionary *item_json = [((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy]; [item_json setObject:minValue forKey:@"min_value"]; [item_json setObject:maxValue forKey:@"max_value"]; [section_json setObject:item_json forKey:item_key]; [self.content_data_download setObject:section_json forKey:section_key]; self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data]; } #pragma mark - WebCell Delegate - (void)commonEditorWebCell:(CommonEditorWebCell *)cell didChangeContentHeight:(CGFloat)contentHeight { // return; NSIndexPath *indexPath = [self.editorTable indexPathForCell:cell]; if (indexPath == nil) { return; } NSMutableDictionary* section_json=nil; NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy]; NSString* subid=[item_json valueForKey:@"subid"]; NSString* control = [item_json valueForKey:@"control"]; id height_obj = [item_json objectForKey:@"height"]; // NSLog(@"indexPath: %@ origin height: %@ currentHeight: %f",indexPath,height_obj,contentHeight); if ([control isEqualToString:@"webview"] && [height_obj floatValue] != contentHeight) { [item_json setValue:@(contentHeight) forKey:@"height"]; if(subid==nil) { section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy]; int count=0; count=[[section_json valueForKey:@"count"] intValue]; for(int i=0;i