// // DetailPageViewController.m // Apex Mobile // // Created by Ray on 14-3-8. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved. // #import "DetailPageViewController.h" //#import "AMShipMap.h" #define DEF_CELL_HEIGHT 44 #define DEF_TABLE_HEIGHT 44 #define LINE_WIDTH 0 #define CELL_MARGIN 15 #define LIST_VMARGIN 15 #define LABEL_MARGIN 0 #define NEW_MAPCELL_MARGIN 8 #import "TabBarController.h" //#import "DetailCellTracking.h" #import #import "DetailCellKVNew.h" #import "DetailCellContainer.h" #import "DetailCellContainerCA.h" #import "MyQLPreviewController.h" #import "LPShareActivity.h" #import "RADataProvider.h" //#import "AMCommEditCell.h" //#import "AMCommHeadCell.h" //#import "AMCommContentCell.h" //#import //#import //#define COMM_ID_HEAD @"COMM_ID_HEAD" //#define COMM_ID_CONTENT @"COMM_ID_CONTENT" //#define COMM_ID_EDIT @"COMM_ID_EDIT" @interface DetailHUD : UIView @property (nonatomic,strong) UILabel *msgLb; @end @implementation DetailHUD + (void)show:(NSString *)msg inView:(UIView *)view { if (!msg) { return; } DetailHUD *hud = [[DetailHUD alloc] initWithFrame:CGRectZero]; hud.backgroundColor = [UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:0.9]; hud.msgLb.text = msg; [hud layoutSize]; for (UIView *sub in view.subviews) { if ([sub isKindOfClass:self]) { sub.hidden = YES; } } [view addSubview:hud]; [hud performSelector:@selector(hide) withObject:nil afterDelay:3.0f]; } - (UILabel *)msgLb { if (!_msgLb) { _msgLb = [[UILabel alloc] initWithFrame:CGRectZero]; _msgLb.textColor = [UIColor whiteColor]; _msgLb.font = [UIFont systemFontOfSize:14.0f]; [self addSubview:_msgLb]; } return _msgLb; } - (void)layoutSize { [self.msgLb sizeToFit]; CGSize size = self.msgLb.bounds.size; CGFloat height = size.height + 20; CGFloat width = size.width + 20; if (height < 30) { height = 30; } if (width < 30) { width = 30; } self.msgLb.center = CGPointMake(width * 0.5, height * 0.5); self.bounds = CGRectMake(0, 0, width, height); self.layer.cornerRadius = 5.0f; self.layer.masksToBounds = YES; } - (void)willMoveToSuperview:(UIView *)newSuperview { [super willMoveToSuperview:newSuperview]; if (newSuperview) { self.center = CGPointMake(newSuperview.bounds.size.width * 0.5, newSuperview.bounds.size.height * 0.5); } } - (void)layoutSubviews { [super layoutSubviews]; if (self.superview) { self.center = CGPointMake(self.superview.bounds.size.width * 0.5, self.superview.bounds.size.height * 0.5); } } - (void)hide { [self removeFromSuperview]; } @end @interface DetailPageViewController () @property (nonatomic,strong) MyQLPreviewController *quickLook; @property (nonatomic,copy) NSString *documentPath; @property (nonatomic,copy) NSString *email; @property (nonatomic,copy) NSString *email_subject; @property (nonatomic,copy) NSString *email_content; //@property (nonatomic,strong) IBOutlet AMShipMap *shipMap; @property (nonatomic,weak) UITableViewCell *editingCell; @property (nonatomic,strong) NSIndexPath *editingIndexPath; @property (nonatomic,strong) NSIndexPath *contactSelectIndexPath; @property (nonatomic,weak) UITapGestureRecognizer *tap; @property (nonatomic,assign) BOOL showKeyboard; @property (nonatomic,strong) NSIndexPath *containerSelectedIndexPath; @end @implementation DetailPageViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } -(void)changeCell { UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200]; reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"refreshing"]; [self performSelector:@selector(ReloadData) withObject:nil afterDelay:1]; DebugLog(@"refresh!!!!!!!!"); } -(void)ReloadData { // Count ++ ; // [mytabelview reloadData]; [self loadpage]; UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200]; [reF endRefreshing]; } - (void)viewDidLoad { [super viewDidLoad]; // self.webviewoprationQueue = [[NSOperationQueue alloc] init]; // self.webviewoprationQueue.maxConcurrentOperationCount = 1; UIRefreshControl *ref = [[UIRefreshControl alloc]init]; ref.tag = 200 ; ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"drag 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(changeCell) forControlEvents:UIControlEventValueChanged]; [self.table addSubview:ref]; if(self.tabBarController.tabBar.hidden==true) { CGRect frame = self.table.frame; frame.size.height +=40; self.table.frame=frame; } // self.view.backgroundColor= [UIColor whiteColor]; [self loadpage]; // Do any additional setup after loading the view. UIBarButtonItem *previewMenuBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"ic_more_dot"] style:UIBarButtonItemStylePlain target:self action:@selector(quickLookMenuClick:)]; self.quickLook.navigationItem.rightBarButtonItem = previewMenuBtn; // [self configureMap]; [self configureTableView]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; NSString *action_type = [self.params objectForKey:@"action_type"]; // if ([action_type isEqualToString:@"Detail"]) { // 避免Tap与Tacking中Cell点击冲突 // [self startListenKeyboard]; // } // // if (self.shipMap) { // [self.shipMap shipMapWillAppear]; // } } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; // [self stopListenKeyboard]; // if (self.shipMap) { // [self.shipMap shipMapWillDisappear]; // } } - (void)configureTableView { // [self.table registerNib:[UINib nibWithNibName:@"AMCommHeadCell" bundle:nil] forCellReuseIdentifier:COMM_ID_HEAD]; // [self.table registerNib:[UINib nibWithNibName:@"AMCommContentCell" bundle:nil] forCellReuseIdentifier:COMM_ID_CONTENT]; // [self.table registerNib:[UINib nibWithNibName:@"AMCommEditCell" bundle:nil] forCellReuseIdentifier:COMM_ID_EDIT]; // } //- (void)configureMap { // // if (!self.showMap) { // // NSArray *constraints = [[self.view constraints] mutableCopy]; // // 删除Table与Map相关约束 // for (NSLayoutConstraint *constaint in constraints) { // if ([constaint.identifier isEqualToString:@"top_constraint"]) { // [self.view removeConstraint:constaint]; // } else if ([constaint.identifier isEqualToString:@"ratio_constraint"]) { // [self.view removeConstraint:constaint]; // } // } // //// // 移除地图 //// [self.shipMap removeFromSuperview]; //// self.shipMap = nil; // // // 设置新约束 // NSLayoutConstraint *top = [NSLayoutConstraint constraintWithItem:self.table // attribute:NSLayoutAttributeTop // relatedBy:NSLayoutRelationEqual // toItem:self.topLayoutGuide // attribute:NSLayoutAttributeBottom // multiplier:1.0 // constant:0]; // [self.view addConstraint:top]; // // // // [self.view layoutIfNeeded]; // } else { // self.shipMap.showCurrent = YES; // self.shipMap.showPoe = YES; // self.shipMap.showPol = YES; // self.shipMap.showPod = YES; // self.shipMap.showPor = YES; // self.shipMap.showOrigin = YES; // self.shipMap.showDestination = YES; // // self.shipMap.delegate = self; // } // //} - (void)saveDocumentClick:(id)sender { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *path = [paths objectAtIndex:0]; NSString *filePath = [path stringByAppendingPathComponent:[self.documentPath lastPathComponent]]; NSError *err; if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) { [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil]; } [[NSFileManager defaultManager] moveItemAtPath:self.documentPath toPath:filePath error:&err]; UIAlertController *alertVC; UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { }]; if (err) { alertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"save document failed:\n%@",err.localizedDescription] preferredStyle:UIAlertControllerStyleAlert]; } else { alertVC = [UIAlertController alertControllerWithTitle:nil message:@"Document Saved" preferredStyle:UIAlertControllerStyleAlert]; } [alertVC addAction:action]; [self presentViewController:alertVC animated:YES completion:nil]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(void) loadpage { // [self.params setValue:[NSString stringWithFormat:@"%d",self.offset] forKey:@"offset"]; // self.prepageButton.enabled=false; // self.nextpageButton.enabled=false; self.mum.center = self.view.center; __weak typeof(self) weakSelf = self; NSTimeInterval animationDuration = 0.30f; [UIView beginAnimations:@"ResizeView" context:nil]; [UIView setAnimationDuration:animationDuration]; self.mum.hidden = false; self.table.hidden = true; [UIView commitAnimations]; // if (self.showMap) { // [self.params setObject:@(YES) forKey:@"request_location"]; // } // if ([[self.params objectForKey:@"action_type"] isEqualToString:@"Detail"]) { // [self.params setObject:@(YES) forKey:@"request_communication"]; // } // [RADataProvider TabDetail:self.params completionHandler:^(NSMutableDictionary *result) { // ; self.content=[RADataProvider json2DetailContent:result]; NSTimeInterval animationDuration = 0.30f; [UIView beginAnimations:@"ResizeView" context:nil]; [UIView setAnimationDuration:animationDuration]; self.mum.hidden = true; if(self.content.result_code!=RESULT_TRUE) { self.table.hidden =false; [self.table reloadData]; UIAlertController *alertVC = [UIAlertController alertControllerWithTitle: @"Warning" message: self.content.err_msg preferredStyle: UIAlertControllerStyleAlert]; UIAlertAction *action_back = [UIAlertAction actionWithTitle:@"Back" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { [weakSelf.navigationController popViewControllerAnimated:false]; }]; UIAlertAction *action_reload = [UIAlertAction actionWithTitle:@"Reload" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { [weakSelf ReloadData]; }]; [alertVC addAction:action_back]; [alertVC addAction:action_reload]; [weakSelf presentViewController:alertVC animated:YES completion:nil]; } else if([self.content get_segmentcount]==0) { self.table.hidden =true; self.norecordLabel.hidden=false; if(self.tabBarController.childViewControllers.count==1) { UIAlertController *alertVC = [UIAlertController alertControllerWithTitle: @"Warning" message: @"No Search Result." preferredStyle: UIAlertControllerStyleAlert]; UIAlertAction *action = [UIAlertAction actionWithTitle:@"Back" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { [weakSelf.navigationController popViewControllerAnimated:false]; }]; [alertVC addAction:action]; [weakSelf presentViewController:alertVC animated:YES completion:nil]; } } else { self.page_menu = result[@"page_menu"]; self.table.hidden =false; [self.table reloadData]; self.email = [self.content.originContent objectForKey:@"email"]; self.email_subject = [self.content.originContent objectForKey:@"email_subject"]; self.email_content = [self.content.originContent objectForKey:@"email_content"]; } [UIView commitAnimations]; // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults]; // bool autologin =[defaults boolForKey:@"autologin"]; // if(!autologin) // { // TabBarController * viewController =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginTabBar"]; // [self presentViewController:viewController animated:YES completion:^{ // // }]; // } // 设置默认选中第一个Container for (NSInteger i = 0; i < self.content.segments.count; i++) { NSMutableDictionary* segment = [self.content.segments[i] mutableCopy]; NSString* type =[segment valueForKey:@"_type"]; // if([type isEqualToString:@"tracking"]) { // NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:i]; // [self.table selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone]; // [self tableView:self.table didSelectRowAtIndexPath:indexPath]; // break; // } } }]; return; // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ // // self.content=[RANetwork get_detailcontent:self.params]; // // // // PageData* pageData=nil; // // if(self.recordCount==-1) // // self.recordCount=[RANetwork get_recordcount: self.params ]; // // if(self.recordCount>0) // // { // // self.pageData=[RANetwork get_pagedata:self.params]; // // // self.pageData=[RANetwork] // // } // // // dispatch_async(dispatch_get_main_queue(), ^{ // // // NSTimeInterval animationDuration = 0.30f; // [UIView beginAnimations:@"ResizeView" context:nil]; // [UIView setAnimationDuration:animationDuration]; // // // self.mum.hidden = true; // if(self.content.result_code!=RESULT_TRUE) // { // self.table.hidden =false; // [self.table reloadData]; // // } // else // if([self.content get_segmentcount]==0) // { // // // self.table.hidden =true; // self.norecordLabel.hidden=false; // // if(self.tabBarController.childViewControllers.count==1) // { // UIAlertController *alertVC = [UIAlertController alertControllerWithTitle: @"Warning" // message: @"No Search Result." // preferredStyle: UIAlertControllerStyleAlert]; // UIAlertAction *action = [UIAlertAction actionWithTitle:@"Back" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { // [weakSelf.navigationController popViewControllerAnimated:false]; // }]; // [alertVC addAction:action]; // [weakSelf presentViewController:alertVC animated:YES completion:nil]; // // } // // // // } // else // { // self.table.hidden =false; // [self.table reloadData]; // // self.email = [self.content.originContent objectForKey:@"email"]; // self.email_subject = [self.content.originContent objectForKey:@"email_subject"]; // self.email_content = [self.content.originContent objectForKey:@"email_content"]; // } // [UIView commitAnimations]; // // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults]; // bool autologin =[defaults boolForKey:@"autologin"]; // if(!autologin) // { // TabBarController * viewController =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginTabBar"]; // [self presentViewController:viewController animated:YES completion:^{ // // }]; // } // // 设置默认选中第一个Container // for (NSInteger i = 0; i < self.content.segments.count; i++) { // // NSMutableDictionary* segment = [self.content.segments[i] mutableCopy]; // NSString* type =[segment valueForKey:@"_type"]; // // if([type isEqualToString:@"tracking"]) { // NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:i]; // [self.table selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone]; // [self tableView:self.table didSelectRowAtIndexPath:indexPath]; // break; // } // } // // // [self.table setNeedsDisplay]; // // if(self.recordCount<2000) // // self.countView.title = [NSString stringWithFormat:@"%d records",self.recordCount]; // // else // // self.countView.title = @"2000+ records"; // // // // if(self.offset=self.recordCount) // // self.nextpageButton.enabled=false; // // else // // self.nextpageButton.enabled=true; // // [self.grid initgrid :self.pageData]; // // // }); // }); } //- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation //{ //// [self.table beginUpdates]; // [self.table reloadData]; //// [self.table endUpdates]; // //} - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator { __weak typeof(self) weakSelf = self; [coordinator animateAlongsideTransition:^(id _Nonnull context) { // 动画前 } completion:^(id _Nonnull context) { // 动画后 [weakSelf.table reloadData]; }]; [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; } //// 是否支持屏幕旋转 //- (BOOL)shouldAutorotate { // // // return YES; //} //// 支持的旋转方向 //- (NSUInteger)supportedInterfaceOrientations { // return UIInterfaceOrientationLandscapeRight;//UIInterfaceOrientationMaskAllButUpsideDown; //} //// 一开始的屏幕旋转方向 //- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { // return UIInterfaceOrientationLandscapeRight; //} - (void)showDocument:(NSString *)url { __weak typeof(self) weakSelf = self; // show alert UIAlertController *alertController = [UIAlertController alertControllerWithTitle: nil message: @"loading..." preferredStyle: UIAlertControllerStyleAlert]; UIViewController *customVC = [[UIViewController alloc] init]; UIActivityIndicatorView* spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; spinner.color = [UIColor darkGrayColor]; [spinner startAnimating]; [customVC.view addSubview:spinner]; [customVC.view addConstraint:[NSLayoutConstraint constraintWithItem: spinner attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:customVC.view attribute:NSLayoutAttributeCenterX multiplier:1.0f constant:0.0f]]; [customVC.view addConstraint:[NSLayoutConstraint constraintWithItem: spinner attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:customVC.view attribute:NSLayoutAttributeCenterY multiplier:1.0f constant:0.0f]]; [alertController setValue:customVC forKey:@"contentViewController"]; [self presentViewController: alertController animated: YES completion: nil]; // NSString *cacheDir = NSTemporaryDirectory(); [RADataProvider DownloadFile:nil url:url completionHandler:^(NSMutableDictionary *result) { // [RANetwork request_download:nil url:url err_record_url:nil offset:0 method:nil storein:cacheDir progressHandler:nil completionHandler:^(NSMutableDictionary *result) { weakSelf.documentPath = nil; [alertController dismissViewControllerAnimated:YES completion:^{ if ([[result objectForKey:@"result"] intValue] == RESULT_TRUE) { NSString *cachePath = [result objectForKey:@"path"]; weakSelf.documentPath = cachePath; if (cachePath) { // push 必须在completion中 [weakSelf.navigationController pushViewController:weakSelf.quickLook animated:YES]; } } else { NSString *msg = [result objectForKey:@"msg"]; UIAlertController *alertVC = [UIAlertController alertControllerWithTitle: @"Warning" message: msg preferredStyle: UIAlertControllerStyleAlert]; UIAlertAction *action = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { }]; [alertVC addAction:action]; [weakSelf presentViewController:alertVC animated:YES completion:nil]; } }]; }]; // [RANetwork request_download:nil url:url completionHandler:^(NSMutableDictionary *result) { // // // }]; // // // download // dispatch_async(dispatch_get_global_queue(0, 0), ^{ // // // NSArray *paths = NSSearchPathForDirectoriesInDomains(nstem, NSUserDomainMask, YES); // // NSString *documents = [paths objectAtIndex:0]; // // NSString *cacheDir = [documents stringByAppendingPathComponent:[module_name stringByAppendingString:@"_download"]]; // // NSString *cacheDir = NSTemporaryDirectory(); // // if (![[NSFileManager defaultManager] fileExistsAtPath:cacheDir]) { // [[NSFileManager defaultManager] createDirectoryAtPath:cacheDir withIntermediateDirectories:NO attributes:nil error:nil]; // } // // // NSString *path = [cacheDir stringByAppendingPathComponent:[NSUUID UUID].UUIDString]; // // // // [RANetwork download_file:nil url:url toCachePath:cacheDir progressHandler:^(NSURLSessionTask *task, double progress) { // // DebugLog(@"download progress %f",progress); // } completionHandler:^(NSMutableDictionary *result) { // // dispatch_async(dispatch_get_main_queue(), ^{ // // weakSelf.documentPath = nil; // [alertController dismissViewControllerAnimated:YES completion:^{ // // // if ([[result objectForKey:@"result"] intValue] == RESULT_TRUE) { // // NSString *cachePath = [result objectForKey:@"path"]; // weakSelf.documentPath = cachePath; // // if (cachePath) { // push 必须在completion中 // [weakSelf.navigationController pushViewController:weakSelf.quickLook animated:YES]; // } // // } else { // // NSString *msg = [result objectForKey:@"msg"]; // // UIAlertController *alertVC = [UIAlertController alertControllerWithTitle: @"Warning" // message: msg // preferredStyle: UIAlertControllerStyleAlert]; // UIAlertAction *action = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { // // }]; // [alertVC addAction:action]; // [weakSelf presentViewController:alertVC animated:YES completion:nil]; // } // // }]; // // // }); // // DebugLog(@"download result %@",result); // // }]; // // // }); } #pragma mark - WKNavigationDelegate - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation { NSLog(@"webview didFinishNavigation"); UITableViewCell *cell = (UITableViewCell *)[[webView superview] superview]; NSIndexPath *indexPath = [self.table indexPathForCell:cell]; if(indexPath==nil) {//for ios7 cell = (UITableViewCell *) webView.superview.superview.superview; indexPath = [self.table indexPathForCell:cell]; } float height= [[self.content.webviewHeight valueForKey:[NSString stringWithFormat:@"%ld",(long)indexPath.section]] floatValue]; if(height>0) return; [webView evaluateJavaScript:@"document.body.scrollHeight;" completionHandler:^(id _Nullable fitHeight,NSError * _Nullable error) { CGRect frame = webView.frame; frame.size.height = [fitHeight floatValue]; //webView.frame = frame; [self.content.webviewHeight setObject:[NSString stringWithFormat:@"%f",frame.size.height/*webView.scrollView.contentSize.height*/] forKey:[NSString stringWithFormat:@"%ld",(long)indexPath.section]]; DebugLog(@"webViewDidFinishLoad ^^^^^^^^^^^^^^^^^reloadRowsAtIndexPaths"); if (![[self.table indexPathsForVisibleRows] containsObject:indexPath]) { //cell 已无法显示。 return; } dispatch_async(dispatch_get_main_queue(), ^{ NSLog(@"reload tableview!!! %f",frame.size.height); // UI更新代码 // [self.table reloadData]; // [self.detailTable reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES]; [self.table reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES]; //[self.editorTable reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone]; }); }]; } //禁止链接跳转 - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler { NSLog(@"%s",__func__); NSLog(@"navigationAction = %@, \r!!!!!!!!!!!!!!!!!!!!!!\n request = %@",navigationAction,navigationAction.request.URL); if(navigationAction.navigationType != WKNavigationTypeLinkActivated) return decisionHandler(WKNavigationActionPolicyAllow); // NSString *currentURL =[webView.request.URL lastPathComponent];// [webView stringByEvaluatingJavaScriptFromString:@"document.title"]; NSString* str = navigationAction.request.URL.absoluteString; if([str isEqualToString:@"about:blank"]) return decisionHandler(WKNavigationActionPolicyAllow);; [self showDocument:navigationAction.request.URL.absoluteString]; return decisionHandler(WKNavigationActionPolicyCancel);; } #pragma mark - Section Switch - (void)sectionSwitchClick:(UIButton *)sender { NSInteger section = sender.tag - 1020; NSMutableArray *segments = [self.content.segments mutableCopy]; NSMutableDictionary* segment = [self.content.segments[section] mutableCopy]; NSString* type =[segment valueForKey:@"_type"]; // if([type isEqualToString:@"tracking"]) // { // BOOL close = [[segment objectForKey:@"close"] boolValue]; // // if (!close) { // close = YES; // } else { // close = NO; // } // [segment setValue:@(close) forKey:@"close"]; // segments[section] = segment; // self.content.segments = segments; //// [self.table reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:UITableViewRowAnimationNone]; // [self.table reloadData]; // } } - (void)copyTap:(UITapGestureRecognizer *)tap { UILabel *lb = (UILabel *)tap.view; UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; pasteboard.string = lb.text; [DetailHUD show:[NSString stringWithFormat:@"%@ Copied",lb.text] inView:self.view]; } #pragma mark - Table view data source // //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section //{ // return 40; //} - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath; { DebugLog(@"heightForRowAtIndexPath"); // float height = [self.content itemHeightAtIndexPath:indexPath]; NSString* type = [self.content get_segmenttype:indexPath.section]; if([type isEqualToString:@"table"]) { // [self.content.webviewHeight setObject:[NSString stringWithFormat:@"%f",webView.frame.size.height] forKey:[NSString stringWithFormat:@"%d",webView.tag]]; float height= [[self.content.webviewHeight valueForKey:[NSString stringWithFormat:@"%ld",(long)indexPath.section]] floatValue]; if(height==0) height=DEF_TABLE_HEIGHT; // DebugLog(@"heightForRowAtIndexPath...............webview,hight = %f section=%ld",height,indexPath.section); //wait(1000); return height; } // else if([type isEqualToString:@"tracking"]) // { // return 64; // } else if([type isEqualToString:@"container"]) { return 100; } else if([type isEqualToString:@"container_ca"]) { return 48; } else if([type isEqualToString:@"mapping"]) { // NSString *CellIdentifier = @"detail_item_kvnew"; // DetailCellKVNew *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row]; NSString* key =[item allKeys][0]; // [cell.keyLabel sizeToFit]; NSString* val=[item valueForKey:key]; if([val isEqual:[NSNull null]]) val=@""; // cell.keyLabel.text = key; // cell.valLabel.htmlText = val; // UILabel* l = [UILabel new]; // l.text =@"Place_Of_Receipt"; // CGSize size= [l sizeThatFits:CGSizeMake(116,MAXFLOAT)]; float width = tableView.frame.size.width; // width-=CELL_MARGIN*2; CGSize constraintkey = CGSizeMake(width*0.4-2*NEW_MAPCELL_MARGIN, MAXFLOAT);//key label width is 40% cell width; CGSize constraintval = CGSizeMake(width*0.6-2*NEW_MAPCELL_MARGIN, MAXFLOAT);//val label width is 60% cell width; /* NSLineBreakByWordWrapping = 0, // Wrap at word boundaries, default NSLineBreakByCharWrapping, // Wrap at character boundaries NSLineBreakByClipping, // Simply clip NSLineBreakByTruncatingHead, // Truncate at head of line: "...wxyz" NSLineBreakByTruncatingTail, */ UIFont * F1=[UIFont systemFontOfSize:13]; UIFont * F2=[UIFont fontWithName:@".SFUIText-Bold" size:13];//[UIFont boldSystemFontOfSize:13]; // [UILabel setFont:]; MDHTMLLabel* keylabel = [MDHTMLLabel new]; keylabel.font = F2; keylabel.numberOfLines = 0; keylabel.lineBreakMode = NSLineBreakByTruncatingTail; keylabel.frame = CGRectMake(0, 0, constraintkey.width, constraintkey.height); keylabel.text=key; CGSize calkeysize= [keylabel sizeThatFits:constraintkey]; if([key isEqualToString:@"Place_Of_Delivery"]) { // int abc=0; } // [keylabel sizeToFit]; // CGRect r = keylabel.frame; MDHTMLLabel* vallabel = [MDHTMLLabel new]; vallabel.font = F1; vallabel.numberOfLines = 0; vallabel.lineBreakMode = NSLineBreakByWordWrapping; vallabel.htmlText=val; vallabel.frame = CGRectMake(0, 0, constraintval.width, constraintval.height); CGSize calvalsize= [vallabel sizeThatFits:constraintval]; float height = MAX(calkeysize.height,calvalsize.height)+NEW_MAPCELL_MARGIN*2; height = MAX(height+LINE_WIDTH, DEF_CELL_HEIGHT); return height; // // NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row]; // NSString* key =[item allKeys][0]; // // [cell.keyLabel sizeToFit]; // NSString* val=[item valueForKey:key]; // if([val isEqual:[NSNull null]]) // val=@""; // if(val==nil) // val=@""; // if([val isEqualToString:@"null"]) // val=@""; // // // // CGRect frame; // frame.size = constraintval; // frame.origin.x=0; // frame.origin.y=0; // RTLabel* rtlabel = [[RTLabel alloc] initWithFrame:frame]; // [rtlabel setLineBreakMode: RTTextLineBreakModeWordWrapping]; // // rtlabel.lineSpacing = 20.0; // [rtlabel setText: val]; // CGSize sizeval=rtlabel.optimumSize; // // // CGSize sizekey = [key sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping]; // // CGSize sizeval = [val sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintval lineBreakMode:NSLineBreakByWordWrapping]; // float height = MAX(sizekey.height,sizeval.height); // height = MAX(height+LINE_WIDTH, DEF_CELL_HEIGHT); // // /* // NSString *text = [items objectAtIndex:[indexPath row]]; // // CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 20000.0f); // // CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap]; // // CGFloat height = MAX(size.height, 44.0f); // // return height + (CELL_CONTENT_MARGIN * 2); // */ // // NSString *CellIdentifier = @"detail_item_kv"; // // DetailCellKV *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; // // NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row]; // // cell.keyLabel.text=[item allKeys][0]; // // [cell.keyLabel sizeToFit]; // // cell.valLabel.text= [item valueForKey:cell.keyLabel.text]; // // [cell.valLabel sizeToFit]; // // // // return MAX(cell.keyLabel.frame.size.height,cell.valLabel.frame.size.height); // return height; } // else if ([type isEqualToString:@"communication"]) { // NSInteger rowCount = [self tableView:tableView numberOfRowsInSection:indexPath.section]; // if (indexPath.row == 0) { // return 118.0f; // } else if (indexPath.row == rowCount - 1) { // // NSMutableDictionary* segment = [self.content.segments[indexPath.section] mutableCopy]; // NSString *edit_content = [segment objectForKey:@"edit_content"]; // // CGFloat h = 40.0f; // 输入框高度,最小40 // if (edit_content && edit_content.length > 0) { // // AMCommEditCell *cell = [[[NSBundle mainBundle] loadNibNamed:@"AMCommEditCell" owner:nil options:nil] objectAtIndex:0]; // // h = [cell heightForContent:edit_content withTableWidth:CGRectGetWidth(tableView.bounds)]; // // if (h < 40.0f) { // h = 40.0f; // } else if (h > 100.0f) { // 输入框高度,最大100 // h = 100.0f; // } // // // } else { // h = 40.0f; // } // // return 50.0f + h; // } else { // // NSMutableDictionary* segment = [self.content.segments[indexPath.section] mutableCopy]; // NSString *itemKey = [NSString stringWithFormat:@"item%ld",indexPath.row - 1]; // NSDictionary *item = [[segment objectForKey:itemKey] mutableCopy]; // // CGFloat height = [[item objectForKey:@"content_height"] floatValue]; // if (height <= 0) { // // NSString *content = [item objectForKey:@"msg"]; // // if (content && content.length > 0) { // NSDictionary *attribute = @{NSFontAttributeName: [UIFont systemFontOfSize:14.0f]}; // // CGSize resSize = [content boundingRectWithSize:CGSizeMake(CGRectGetWidth(tableView.bounds) - 11, MAXFLOAT) // options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading) // attributes:attribute // context:nil].size; // height = resSize.height; // } else { // height = 0; // } // // [item setValue:@(height) forKey:@"content_height"]; // [segment setObject:item forKey:itemKey]; // // NSMutableArray *arr = [self.content.segments mutableCopy]; // [arr replaceObjectAtIndex:indexPath.section withObject:segment]; // self.content.segments = arr; // } // // return 71.5 + height; // } // } else if([type isEqualToString:@"log"]) { DebugLog(@"cellForRowAtIndexPath =====> list"); float width = tableView.frame.size.width; width-=CELL_MARGIN*2; CGSize constraintval = CGSizeMake(width, 20000.0f);//val label width is 60% cell width; NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row]; NSString* text=item[@"text"]; if([text isEqual:[NSNull null]]) text=@""; if(text==nil) text=@""; if([text isEqualToString:@"null"]) text=@""; // CGRect frame; // frame.size = constraintval; // frame.origin.x=0; // frame.origin.y=0; // CGSize sizeText = [text sizeWithFont:[UIFont systemFontOfSize:13.0] constrainedToSize:constraintval lineBreakMode:NSLineBreakByWordWrapping]; // CGSize sizeval = [val sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintval lineBreakMode:NSLineBreakByWordWrapping]; CGSize sizeText = [text boundingRectWithSize:constraintval options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading) attributes: @{NSFontAttributeName: [UIFont systemFontOfSize:13.0]} context:nil].size; // UILabel* label = [UILabel new]; // label.frame= CGRectMake(0, 0, width, 2000.0f); // // label.font =[UIFont systemFontOfSize:13.0]; // // CGSize bestsize=[label sizeThatFits:constraintval]; float height = sizeText.height; height = MAX(height+LINE_WIDTH+LIST_VMARGIN, DEF_CELL_HEIGHT); return ceilf(height); } else { DebugLog(@"cellForRowAtIndexPath =====> list"); float width = tableView.frame.size.width; width-=CELL_MARGIN*2; CGSize constraintval = CGSizeMake(width, 20000.0f);//val label width is 60% cell width; NSDictionary* item = self.content.segments[indexPath.section]; NSString* text=[item valueForKey:[NSString stringWithFormat:@"line%ld",(long)indexPath.row]]; if([text isEqual:[NSNull null]]) text=@""; if(text==nil) text=@""; if([text isEqualToString:@"null"]) text=@""; // CGRect frame; // frame.size = constraintval; // frame.origin.x=0; // frame.origin.y=0; // CGSize sizeText = [text sizeWithFont:[UIFont systemFontOfSize:13.0] constrainedToSize:constraintval lineBreakMode:NSLineBreakByWordWrapping]; // CGSize sizeval = [val sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintval lineBreakMode:NSLineBreakByWordWrapping]; CGSize sizeText = [text boundingRectWithSize:constraintval options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading) attributes: @{NSFontAttributeName: [UIFont systemFontOfSize:13.0]} context:nil].size; float height = sizeText.height; height = MAX(height+LINE_WIDTH+LIST_VMARGIN, DEF_CELL_HEIGHT); return ceilf(height); } // return height; } //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section //{ // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)]; // myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7]; // UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 90, 22)]; // titleLabel.textColor=[UIColor whiteColor]; // titleLabel.backgroundColor = [UIColor clearColor]; // titleLabel.text =[self.content get_segmentname:section]; // [titleLabel sizeToFit]; // [myView addSubview:titleLabel]; // // return myView; //} //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section //{ // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)]; // myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7]; //// UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 90, 22)]; //// titleLabel.textColor=[UIColor whiteColor]; //// titleLabel.backgroundColor = [UIColor grayColor]; //// titleLabel.text =[self.content get_segmentname:section]; //// [titleLabel sizeToFit]; //// [myView addSubview:titleLabel]; // // return myView; //} - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { DebugLog(@"numberOfSectionsInTableView=%ld",[self.content get_segmentcount]); return [self.content get_segmentcount]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { DebugLog(@"numberOfRowsInSection=%d",[self.content get_itemcount:section]); NSMutableDictionary* segment = [self.content.segments[section] mutableCopy]; NSString* type =[segment valueForKey:@"_type"]; if ([type isEqualToString:@"communication"]) { return [self.content get_itemcount:section] + 2; } else { return [self.content get_itemcount:section]; } } - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { DebugLog(@"titleForHeaderInSection=%@",[self.content get_segmentname:section]); return [self.content get_segmentname:section]; } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { NSMutableDictionary* segment = [self.content.segments[section] mutableCopy]; NSString* type =[segment valueForKey:@"_type"]; CGFloat w = tableView.frame.size.width; UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, w, 30)]; UILabel *titleLb = [[UILabel alloc] initWithFrame:CGRectMake(5, 0, w - 100, 30)]; titleLb.font = [UIFont systemFontOfSize:15.0f]; titleLb.textColor = APGRAYCOLOR; titleLb.text = [self tableView:tableView titleForHeaderInSection:section]; [header addSubview:titleLb]; // if([type isEqualToString:@"tracking"]) // { // BOOL close = [[segment objectForKey:@"close"] boolValue]; // NSString *title = @"Show"; // if (!close) { // title = @"Hide"; // } else { // title = @"Show"; // } // // UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; // btn.frame = CGRectMake(w - 70, 0, 60, 30); // btn.tag = 1020 + section; // [btn setTitle:title forState:UIControlStateNormal]; // [btn setTitleColor:APGRAYCOLOR forState:UIControlStateNormal]; // [btn addTarget:self action:@selector(sectionSwitchClick:) forControlEvents:UIControlEventTouchUpInside]; // // [header addSubview:btn]; // // // Tap Copy // UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(copyTap:)]; // tapGesture.numberOfTapsRequired = 2; // [titleLb addGestureRecognizer:tapGesture]; // titleLb.userInteractionEnabled = YES; // } return header; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 30; } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return 0.0001; } //- (UIImage *) imageWithTintColor:(UIImage*)source Color:(UIColor *)tintColor blendMode:(CGBlendMode)blendMode { // //We want to keep alpha, set opaque to NO; Use 0.0f for scale to use the scale factor of the device’s main screen. // UIGraphicsBeginImageContextWithOptions(source.size, NO, 0.0f); [tintColor setFill]; // CGRect bounds = CGRectMake(0, 0, source.size.width, source.size.height); UIRectFill(bounds); // //Draw the tinted image in context // [source drawInRect:bounds blendMode:blendMode alpha:1.0f]; // if (blendMode != kCGBlendModeDestinationIn) // { // [source drawInRect:bounds blendMode:kCGBlendModeDestinationIn alpha:1.0f]; // } // UIImage *tintedImage = UIGraphicsGetImageFromCurrentImageContext(); // UIGraphicsEndImageContext(); // return tintedImage; //} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { // NSString *CellIdentifier = @"testcell"; // return [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; NSString* type = [self.content get_segmenttype:indexPath.section]; if([type isEqualToString:@"table"]) { DebugLog(@"cellForRowAtIndexPath =====> table"); static NSString *CellIdentifier = @"detail_item_web"; DetailCellWeb *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row]; NSString* tablecontent = [item valueForKey:@"content"]; cell.webView.tag = indexPath.section; // cell.webView.scrollView.contentSize.height = 0; cell.webView.scrollView.bounces=NO; cell.webView.scrollView.directionalLockEnabled = true; CGSize size= cell.webView.scrollView.contentSize; size.height=10; cell.webView.scrollView.contentSize=size; cell.webView.navigationDelegate=self; // nsstring* c = [NSString stringwith] // NSString *filePath = [[NSBundle mainBundle]pathForResource:@"about" ofType:@"htm"]; // NSString *htmlString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil]; [cell.webView loadHTMLString:tablecontent baseURL:nil]; // dispatch_async(dispatch_get_main_queue(), ^{ // // wait(5000); // DebugLog(@"!!!!!!!!!!!!!!!!!!!!!!!!!!!webview section=%ld height=%f",indexPath.section,cell.webView.scrollView.contentSize.height); // //// DebugLog(@"url:%@", [self.webView stringByEvaluatingJavaScriptFromString:@"window.location.href;"]); // shows google.com instead of about:blank // }); // CGRect rect = cell.webView.frame; // [self.content set_itemheight:cell.webView.frame.size.height AtIndexPath:indexPath]; // [cell.webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:filePath]]; return cell; } // else if([type isEqualToString:@"tracking"]) // { // DebugLog(@"cellForRowAtIndexPath =====> table"); // // static NSString *CellIdentifier = @"detail_item_tracking"; // // DetailCellTracking *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; // NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row]; // // if(indexPath.row==0) // { // cell.trackingIcon.tintColor=UIColorFromRGB(0x1e7ffb); // cell.trackingIcon.image = [[UIImage imageNamed:item[@"icon"]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; // } // else // { // cell.trackingIcon.tintColor=[UIColor grayColor]; // cell.trackingIcon.image = [[UIImage imageNamed:item[@"icon"]] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; // } // // // cell.trackingMsg.text=item[@"msg"]; //// NSString* tablecontent = [item valueForKey:@"content"]; //// cell.webView.tag = indexPath.section; //// // cell.webView.scrollView.contentSize.height = 0; //// cell.webView.scrollView.bounces=NO; //// cell.webView.scrollView.directionalLockEnabled = true; //// CGSize size= cell.webView.scrollView.contentSize; //// size.height=10; //// cell.webView.scrollView.contentSize=size; //// //// //// [cell.webView loadHTMLString:tablecontent baseURL:nil]; // // return cell; // } else if([type isEqualToString:@"container"]) { NSString *CellIdentifier = @"detail_item_container"; DetailCellContainer *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row]; cell.labelCMB.text = item[@"cmb"]; cell.labelQTY.text = item[@"qty"]; cell.labelWeight.text = item[@"weight"]; cell.labelSize.text = item[@"size"]; cell.labelContainerNo.text = item[@"container#"]; cell.labelService.text=item[@"service"]; cell.labelSealNo.text=item[@"seal_no"]; //cell.tapDelegate = self; // UIView * lineview = [[LineView alloc] initWithFrame:cell.contentView.frame]; // lineview.userInteractionEnabled = NO;// 不设为NO会屏蔽cell的点击事件 // lineview.backgroundColor = [UIColor clearColor];// 设为透明从而使得cell.backgroundColor有效. // lineview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; // [cell.contentView addSubview:lineview];// cell.contentView是个readonly属性,所以别想着替换contentView了. return cell; } else if([type isEqualToString:@"container_ca"]) { NSString *CellIdentifier = @"detail_item_container_ca"; DetailCellContainerCA *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row]; cell.labelContainerNo.text = item[@"container#"]; cell.labelSealNo.text=item[@"seal_no"]; //cell.tapDelegate = self; // UIView * lineview = [[LineView alloc] initWithFrame:cell.contentView.frame]; // lineview.userInteractionEnabled = NO;// 不设为NO会屏蔽cell的点击事件 // lineview.backgroundColor = [UIColor clearColor];// 设为透明从而使得cell.backgroundColor有效. // lineview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; // [cell.contentView addSubview:lineview];// cell.contentView是个readonly属性,所以别想着替换contentView了. return cell; } else if([type isEqualToString:@"mapping"]) { NSString *CellIdentifier = @"detail_item_kvnew"; DetailCellKVNew *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row]; NSString* key =[item allKeys][0]; // [cell.keyLabel sizeToFit]; NSString* val=[item valueForKey:key]; // if([val isEqual:[NSNull null]]) // val=@""; cell.keyLabel.text = key; cell.valLabel.htmlText = val; // if([key isEqualToString:@"Place_Of_Delivery"]) // { //// int abc=0; // } NSLog(@"key %@ val %@",key,val); cell.tapDelegate = self; // UIView * lineview = [[LineView alloc] initWithFrame:cell.contentView.frame]; // lineview.userInteractionEnabled = NO;// 不设为NO会屏蔽cell的点击事件 // lineview.backgroundColor = [UIColor clearColor];// 设为透明从而使得cell.backgroundColor有效. // lineview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; // [cell.contentView addSubview:lineview];// cell.contentView是个readonly属性,所以别想着替换contentView了. return cell; // float width = tableView.frame.size.width; // // width-=CELL_MARGIN*2; // CGSize constraintkey = CGSizeMake(width*0.4-2*LABEL_MARGIN, 20000.0f);//key label width is 40% cell width; // CGSize constraintval = CGSizeMake(width*0.6-2*LABEL_MARGIN, 20000.0f);//val label width is 60% cell width; // NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row]; // NSString* key =[item allKeys][0]; // // [cell.keyLabel sizeToFit]; // NSString* val=[item valueForKey:key]; // if([val isEqual:[NSNull null]]) // val=@""; // if(val==nil) // val=@""; // if([val isEqualToString:@"null"]) // val=@""; // // // // // CGRect frame; // frame.size = constraintval; // frame.origin.x=0; // frame.origin.y=0; // RTLabel* rtlabel = [[RTLabel alloc] initWithFrame:frame]; // [rtlabel setLineBreakMode: RTTextLineBreakModeWordWrapping]; // // rtlabel.lineSpacing = 20.0; // [rtlabel setText: val]; // CGSize sizeval=rtlabel.optimumSize; // CGSize sizekey = [key sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping]; // // CGSize sizeval = [val sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintval lineBreakMode:NSLineBreakByWordWrapping]; //// DebugLog(@"tableView width:%f",width); //// //// DebugLog(@"key width= %f val width = %f",constraintkey.width,constraintval.width); //// DebugLog(@"key = %@ val = %@",key,val); // float height = MAX(sizekey.height,sizeval.height); // height = MAX(height, DEF_CELL_HEIGHT-LINE_WIDTH); // sizekey.height = height; // sizekey.width = constraintkey.width; // // sizeval.height = height; // sizeval.width =constraintval.width; // // NSString *CellIdentifier = @"detail_item_kv"; // DetailCellKV *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; // if(cell==nil) // DebugLog(@"cell is nil........................."); // // // // CGRect framekey ; // // framekey.origin.x=CELL_MARGIN; // // framekey.origin.y=LINE_WIDTH; // // framekey.size = sizekey; // // UILabel* keyLabel = [[UILabel alloc]initWithFrame:framekey]; // // keyLabel.lineBreakMode = NSLineBreakByWordWrapping; // // keyLabel.backgroundColor = [UIColor grayColor]; // // keyLabel.text = key; // // // // CGRect frameval; // // frameval.origin.x=constraintkey.width+CELL_MARGIN; // // frameval.origin.y=LINE_WIDTH; // // frameval.size = sizeval; // // // // UILabel* valLabel = [[UILabel alloc]initWithFrame:frameval]; // // valLabel.lineBreakMode = NSLineBreakByWordWrapping; // // valLabel.text = val; // // // // for(UIView* v in cell.contentView.subviews) // // { // // [v removeFromSuperview]; // // // // } // // // // [cell.contentView addSubview:keyLabel]; // // [cell.contentView addSubview:valLabel]; // // // CGRect framekey = cell.keyLabel.frame; // framekey.origin.x=CELL_MARGIN+LABEL_MARGIN; // framekey.origin.y=LINE_WIDTH; // framekey.size = sizekey; // cell.keyLabel.frame = framekey; // cell.keyLabel.text=key; // CGRect frameval = cell.valLabel.frame; // frameval.origin.x=constraintkey.width+CELL_MARGIN+3*LABEL_MARGIN; //2 margin for key 1 margin for value self // frameval.origin.y=LINE_WIDTH; // frameval.size = sizeval; // cell.valLabel.frame = frameval; // // [cell.valLabel setTextAlignment:RTTextAlignmentCenter]; // cell.valLabel.text= val; // CGPoint rcenter; // rcenter.x = width * 0.4+width * 0.6/2; // rcenter.y = height /2; // cell.valLabel.center=rcenter; //// cell.valLabel.backgroundColor =[UIColor redColor]; // //// cell.contentView.superview.backgroundColor = [UIColor clearColor]; //// cell.backgroundColor = [UIColor whiteColor]; // UIView * lineview = [[LineView alloc] initWithFrame:cell.contentView.frame]; // lineview.userInteractionEnabled = NO;// 不设为NO会屏蔽cell的点击事件 // lineview.backgroundColor = [UIColor clearColor];// 设为透明从而使得cell.backgroundColor有效. // lineview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; // [cell.contentView addSubview:lineview];// cell.contentView是个readonly属性,所以别想着替换contentView了. // // // // // [cell.valLabel sizeToFit]; // // cell.anameLabel.text = [field valueForKey:@"aname"]; // // [cell.anameLabel sizeToFit]; // // DebugLog(@"cellForRowAtIndexPath%@",[field valueForKey:@"aname"]); // // Configure the cell... // // CGRect rect = cell.frame; // // [self.content set_itemheight:100 AtIndexPath:indexPath]; // return cell; } // else if ([type isEqualToString:@"communication"]) { // // NSInteger rowCount = [tableView numberOfRowsInSection:indexPath.section]; // // NSMutableDictionary* segment = [self.content.segments[indexPath.section] mutableCopy]; // // if (indexPath.row == 0) { // head // // AMCommHeadCell *cell = [tableView dequeueReusableCellWithIdentifier:COMM_ID_HEAD forIndexPath:indexPath]; // // NSString *to = [segment objectForKey:@"receipt"]; // NSString *cc = [segment objectForKey:@"cc"]; // // [cell setTo:to]; // [cell setCc:cc]; // // cell.delegate = self; // // return cell; // // } else if (indexPath.row == rowCount - 1) { // edit // // AMCommEditCell *cell = [tableView dequeueReusableCellWithIdentifier:COMM_ID_EDIT forIndexPath:indexPath]; // // NSString *editContent = [segment objectForKey:@"edit_content"]; // [cell setEmail:editContent]; // cell.delegate = self; // // return cell; // // } else { // content // // AMCommContentCell *cell = [tableView dequeueReusableCellWithIdentifier:COMM_ID_CONTENT forIndexPath:indexPath]; // // NSDictionary *item = [segment objectForKey:[NSString stringWithFormat:@"item%ld",indexPath.row - 1]]; // // NSString *sender = [item objectForKey:@"Sender"]; // NSString *content = [item objectForKey:@"msg"]; // NSString *time = [item objectForKey:@"mst_time"]; // NSString *email = [item objectForKey:@"email_url"]; // // // [cell setSender:sender]; // [cell setContent:content]; // [cell setTime:time]; // [cell setEmail:email]; // // cell.delegate = self; // // return cell; // // } // } else if([type isEqualToString:@"log"]) { DebugLog(@"cellForRowAtIndexPath =====> list"); static NSString *CellIdentifier = @"detail_item_list"; // float width = tableView.frame.size.width; // // width-=CELL_MARGIN*2; // CGSize constraintkey = CGSizeMake(width, 20000.0f);//key label width is 40% cell width; // NSDictionary* item = self.content.segments[indexPath.section]; NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row]; NSString* val=item[@"text"]; bool bg =[item[@"bg"] boolValue]; if([val isEqual:[NSNull null]]) val=@""; if(val==nil) val=@""; if([val isEqualToString:@"null"]) val=@""; // CGSize sizeval = [val sizeWithFont:[UIFont systemFontOfSize:13.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping]; // CGSize sizeval = [val boundingRectWithSize:constraintkey options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading) attributes: @{NSFontAttributeName: [UIFont systemFontOfSize:13.0]} context:nil].size; // // float height = sizeval.height; // height = MAX(height, DEF_CELL_HEIGHT-LINE_WIDTH); // sizeval.height = height; // sizeval.width = constraintkey.width; //创建cell DetailCellList *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; // CGRect framekey = cell.listLabel.frame; // framekey.origin.x=CELL_MARGIN; // framekey.origin.y=LINE_WIDTH; // framekey.size = sizeval; // cell.listLabel.frame = framekey; cell.listLabel.text= val; if(bg) cell.contentView.backgroundColor = LogBGColor1; else cell.contentView.backgroundColor = LogBGColor0; return cell; } else { DebugLog(@"cellForRowAtIndexPath =====> list"); static NSString *CellIdentifier = @"detail_item_list"; // float width = tableView.frame.size.width; // // width-=CELL_MARGIN*2; // CGSize constraintkey = CGSizeMake(width, 20000.0f);//key label width is 40% cell width; // NSDictionary* item = self.content.segments[indexPath.section]; NSString* val=[item valueForKey:[NSString stringWithFormat:@"line%ld",(long)indexPath.row]]; if([val isEqual:[NSNull null]]) val=@""; if(val==nil) val=@""; if([val isEqualToString:@"null"]) val=@""; // CGSize sizeval = [val sizeWithFont:[UIFont systemFontOfSize:13.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping]; // CGSize sizeval = [val boundingRectWithSize:constraintkey options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading) attributes: @{NSFontAttributeName: [UIFont systemFontOfSize:13.0]} context:nil].size; // // float height = sizeval.height; // height = MAX(height, DEF_CELL_HEIGHT-LINE_WIDTH); // sizeval.height = height; // sizeval.width = constraintkey.width; //创建cell DetailCellList *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; // CGRect framekey = cell.listLabel.frame; // framekey.origin.x=CELL_MARGIN; // framekey.origin.y=LINE_WIDTH; // framekey.size = sizeval; // cell.listLabel.frame = framekey; cell.listLabel.text= val; return cell; } return nil; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSMutableDictionary* segment = [self.content.segments[indexPath.section] mutableCopy]; NSString* type =[segment valueForKey:@"_type"]; NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row]; if(([type isEqualToString: @"container"]||[type isEqualToString: @"container_ca"])&& [item[@"commodity"] boolValue]) { NSString* cid=[item[@"id"] stringValue]; NSMutableDictionary* param =[NSMutableDictionary new]; param[@"action"]=@"detail"; param[@"sub_type"]=@"container"; param[@"action_type"]=@"Container Detail"; param[@"id"]= cid; UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Detail" bundle:[NSBundle mainBundle]]; DetailPageViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"DetailPageViewController"]; vc.function_name = @"Container Detail"; vc.params = param; [vc setTitle:@"Container Detail"]; // ResultViewController *vc = [ResultViewController resultViewController:params]; [self.navigationController pushViewController:vc animated:YES]; } // NSString* port = self.content.originContent[@"backup_port"]; // if([type isEqualToString:@"tracking"]) { // NSDictionary *location = [segment objectForKey:@"location"]; // [self.shipMap showShipAnnotaion:location backupLocation:port]; // self.containerSelectedIndexPath = indexPath; // } } #pragma mark - Quick Look - (MyQLPreviewController *)quickLook { if (!_quickLook) { _quickLook = [[MyQLPreviewController alloc] init]; _quickLook.delegate = self; _quickLook.dataSource = self; } else { [_quickLook reloadData]; } return _quickLook; } #pragma mark - QuickLook Data Source - (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller { return 1; } - (id ) previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index { return [NSURL fileURLWithPath:self.documentPath]; } #pragma mark - QuickLook Delegate - (void) previewControllerDidDismiss:(QLPreviewController *)controller { } /** * 文件内部链接点击不进行外部跳转 */ - (BOOL) previewController:(QLPreviewController *)controller shouldOpenURL:(NSURL *)url forPreviewItem:(id)item { return NO; } #pragma mark - KVDetail Tap Delegate - (void)detailCell:(DetailCellKVNew *)cell doubleTapedForValue:(NSString *)value { // NSIndexPath *indexPath = [self.table indexPathForCell:cell]; UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; pasteboard.string = value; [DetailHUD show:[NSString stringWithFormat:@"%@ Copied",cell.keyLabel.text] inView:self.view]; } #pragma mark - Quick Look Menu Action - (void)saveDocument { NSMutableDictionary *emailInfo = [NSMutableDictionary new]; if (self.email.length==0) { self.email=@""; } if (self.email_subject.length==0) { self.email_subject=@""; } if (self.email_content.length==0) { self.email_content=@""; } [emailInfo setValue:self.email forKey:@"reciptions"]; [emailInfo setValue:self.email_subject forKey:@"subject"]; [emailInfo setValue:self.email_content forKey:@"content"]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *path = [paths objectAtIndex:0]; NSString *filePath = [path stringByAppendingPathComponent:[self.documentPath lastPathComponent]]; NSString *emailPath = [path stringByAppendingPathComponent:[NSString stringWithFormat:@".%@",[[self.documentPath stringByDeletingPathExtension] lastPathComponent]]]; NSError *err; if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) { [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil]; } [[NSFileManager defaultManager] moveItemAtPath:self.documentPath toPath:filePath error:&err]; NSData* saved_email_data = [RAConvertor dict2data:emailInfo]; [saved_email_data writeToFile:emailPath atomically:NO]; UIAlertController *alertVC; UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { }]; if (err) { alertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"save document failed:\n%@",err.localizedDescription] preferredStyle:UIAlertControllerStyleAlert]; } else { alertVC = [UIAlertController alertControllerWithTitle:nil message:@"Document Saved" preferredStyle:UIAlertControllerStyleAlert]; } [alertVC addAction:action]; [self presentViewController:alertVC animated:YES completion:nil]; } - (void)shareDocument { return [self share_activity]; } -(void) share_activity { // 设置分享内容 // NSString *text = @"分享内容"; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *path = [paths objectAtIndex:0]; NSString *filePath = [path stringByAppendingPathComponent:[self.documentPath lastPathComponent]]; // 没有保存的情况 if ([[NSFileManager defaultManager] fileExistsAtPath:self.documentPath]) { filePath = self.documentPath; } NSURL *url = [NSURL fileURLWithPath:filePath]; NSArray *activityItems = @[url]; LPShareActivity *share = [[LPShareActivity alloc] init]; share.to = [self.email componentsSeparatedByString:@","];//@[@"676767@qq.com"]; share.subject = self.email_subject;//@"test subject"; share.body = self.email_content;// @"body"; share.filePath = filePath; share.handle = ^(UIViewController *vc) { [self presentViewController:vc animated:YES completion:^{ // [share activityDidFinish:YES]; // ... }]; }; // 服务类型控制器 UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:@[share]]; // _activityViewController = activityViewController; // activityViewController.excludedActivityTypes = @[UIActivityTypeMail]; activityViewController.modalInPopover = true; [self presentViewController:activityViewController animated:YES completion:nil]; // 选中分享类型 [activityViewController setCompletionWithItemsHandler:^(NSString * __nullable activityType, BOOL completed, NSArray * __nullable returnedItems, NSError * __nullable activityError){ // 显示选中的分享类型 NSLog(@"act type %@",activityType); if (completed) { NSLog(@"ok"); }else { NSLog(@"not ok"); } }]; } - (void)quickLookMenuClick:(id)sender { UIAlertController *menuAlert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet]; __weak typeof(self) weakSelf = self; UIAlertAction *saveAction = [UIAlertAction actionWithTitle:@"Save Document" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { [weakSelf saveDocument]; }]; UIAlertAction *shareAction = [UIAlertAction actionWithTitle:@"Share Document" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { [weakSelf shareDocument]; }]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { }]; // [menuAlert addAction:saveAction]; [menuAlert addAction:shareAction]; [menuAlert addAction:cancelAction]; [self presentViewController:menuAlert animated:YES completion:nil]; } // //#pragma mark - Keyboard // //- (void)startListenKeyboard { // NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; // // 键盘通知 // [notificationCenter addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; // [notificationCenter addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; // [notificationCenter addObserver:self selector:@selector(keyboardChangeFrame:) name:UIKeyboardDidChangeFrameNotification object:nil]; // // UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapToHideKeyboard:)]; // [self.view addGestureRecognizer:tap]; // self.tap = tap; //} // //- (void)stopListenKeyboard { // NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; // [notificationCenter removeObserver:self]; // // [self.view removeGestureRecognizer:self.tap]; //} // //- (void)tapToHideKeyboard:(UITapGestureRecognizer *)tap { // [self.view endEditing:YES]; //} // ///**键盘隐藏*/ //- (void)keyboardWillHide:(NSNotification *)notification { // NSLog(@"keyboard hide"); // self.showKeyboard = NO; //} // ///**键盘显示*/ //- (void)keyboardWillShow:(NSNotification *)notification { // //// NSTimeInterval duration = [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]; //// CGRect begin = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue]; //// CGRect end = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; //// //// if (duration == 0) { //// duration = 0.25; //// } // NSLog(@"keyboard show"); // self.showKeyboard = YES; //} // ///**在使用过程中切换键盘*/ //- (void)keyboardChangeFrame:(NSNotification *)notification { // // NSLog(@"keyboard change frame"); // // NSTimeInterval duration = [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]; //// CGRect begin = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue]; // CGRect end = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; // // if (duration == 0) { // duration = 0.25; // } // // NSLayoutConstraint *bottom_constraint = nil; // for (NSLayoutConstraint *constraint in self.view.constraints) { // if ([constraint.identifier isEqualToString:@"table_bottom_constraint"]) { // bottom_constraint = constraint; // break; // } // } // // CGFloat tabBarY = CGRectGetMinY(self.tabBarController.tabBar.frame); // // CGFloat offset = tabBarY - CGRectGetMinY(end); // if (offset < 0) { // offset = 0; // } // // if (bottom_constraint) { // bottom_constraint.constant = offset; // [self.view layoutIfNeeded]; // // if (self.editingIndexPath) { // [self.table scrollToRowAtIndexPath:self.editingIndexPath atScrollPosition:UITableViewScrollPositionNone animated:UITableViewRowAnimationNone]; // } // } // // CGSize contentSize = self.table.contentSize; // CGPoint contentOffset = self.table.contentOffset; // offset = contentOffset.y - (contentSize.height - CGRectGetHeight(self.table.bounds)); // if (offset > 0) { // contentOffset.y -= offset; // self.table.contentOffset = contentOffset; // } // //} //#pragma mark - COMM Head Delegate // //- (void)commHeadCell:(AMCommHeadCell *)cell didChangeCC:(NSString *)cc { // // NSIndexPath *indexPath = [self.table indexPathForCell:cell]; // // [self cc:cc changedForIndexPath:indexPath]; //} // //- (void)commHeadCell:(AMCommHeadCell *)cell didBeginEditing:(UITextField *)textField { // self.editingCell = cell; // self.editingIndexPath = [self.table indexPathForCell:cell]; //} // //- (void)commHeadCell:(AMCommHeadCell *)cell didEndEditing:(UITextField *)textField { // self.editingCell = nil; // self.editingIndexPath = nil; //} // //- (void)commHeadCell:(AMCommHeadCell *)cell didClickContactButton:(UIButton *)button { // // self.contactSelectIndexPath = [self.table indexPathForCell:cell]; // // CNContactPickerViewController *contactVC = [[CNContactPickerViewController alloc] init]; // contactVC.delegate = self; // // // [self presentViewController:contactVC animated:YES completion:nil]; //} // //#pragma mark - COMM Content Delegate // //- (void)commContentCell:(AMCommContentCell *)cell sendEmail:(NSString *)email { // //// MFMailComposeViewController *emailVC = [[MFMailComposeViewController alloc] init]; //// if (!emailVC) { //// //// return; //// } //// [emailVC setMessageBody:[NSString stringWithFormat:@"%@",email] isHTML:YES]; //// //// [self presentViewController:emailVC animated:YES completion:nil]; // // NSURL *url = [NSURL URLWithString:email]; // if ([[UIApplication sharedApplication] canOpenURL:url]) { // [[UIApplication sharedApplication] openURL:url]; // } // //} // //#pragma mark - COMM Edit Delegate // //- (void)commEditCell:(AMCommEditCell *)cell clickToSendEmail:(NSString *)email { // // // 检查Email内容是否为空 // if (!email || email.length == 0) { // // UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Warning" message:@"The communication message that will be sent is blank" preferredStyle:UIAlertControllerStyleAlert]; // UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { // // }]; // [alert addAction:okAction]; // [self presentViewController:alert animated:YES completion:nil]; // return; // } // // NSIndexPath *indexPath = [self.table indexPathForCell:cell]; // NSMutableDictionary* segment = [self.content.segments[indexPath.section] mutableCopy]; // NSString *cc = [segment objectForKey:@"cc"]; // if (cc && cc.length > 0) { // // // 校验邮箱地址格式是否有效 // NSArray *ccArr = [cc componentsSeparatedByString:@";"]; // for (NSString *ccStr in ccArr) { // if (ccStr.length > 0) { // BOOL isEmail = [self validateEmail:ccStr]; // if (!isEmail) { // UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Warning" message:@"The communication cc is not right" preferredStyle:UIAlertControllerStyleAlert]; // UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { // // }]; // [alert addAction:okAction]; // [self presentViewController:alert animated:YES completion:nil]; // return; // } // } // } // // // 校验通过 // // } // // UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:@"send email" preferredStyle:UIAlertControllerStyleAlert]; // [self presentViewController:alert animated:YES completion:nil]; // // NSString *serialNo = [segment objectForKey:@"serial_no"]; // // __weak typeof(self) weakSelf = self; // // [RANetwork request_sendemail:email CC:cc SerialNo:serialNo completionHandler:^(NSMutableDictionary *result) { // NSDictionary *sendResponse=result; // [alert dismissViewControllerAnimated:YES completion:^{ // // if (weakSelf) { // __strong typeof(weakSelf) strongSelf = weakSelf; // int result = [[sendResponse objectForKey:@"result"] intValue]; // // if (result == RESULT_TRUE) { // // } else { // NSString *msg = [sendResponse objectForKey:@"err_msg"]; // if (msg == nil) { // msg = @"Sorry,something wrong"; // } // UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:msg preferredStyle:UIAlertControllerStyleAlert]; // UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { // // }]; // [alert addAction:okAction]; // [strongSelf presentViewController:alert animated:YES completion:nil]; // } // // } // // }]; // }]; // // return; // // dispatch_async(dispatch_get_global_queue(0, 0), ^{ // NSDictionary *sendResponse = [RANetwork sendEmail:email CC:cc SerialNo:serialNo]; // dispatch_async(dispatch_get_main_queue(), ^{ // // [alert dismissViewControllerAnimated:YES completion:^{ // // if (weakSelf) { // __strong typeof(weakSelf) strongSelf = weakSelf; // int result = [[sendResponse objectForKey:@"result"] intValue]; // // if (result == RESULT_TRUE) { // // } else { // NSString *msg = [sendResponse objectForKey:@"err_msg"]; // if (msg == nil) { // msg = @"Sorry,something wrong"; // } // UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:msg preferredStyle:UIAlertControllerStyleAlert]; // UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { // // }]; // [alert addAction:okAction]; // [strongSelf presentViewController:alert animated:YES completion:nil]; // } // // } // // }]; // // }); // }); // // //} // //- (void)commEditCell:(AMCommEditCell *)cell didChangeEmail:(NSString *)email { // // 保存数据 // NSIndexPath *indexPath = [self.table indexPathForCell:cell]; // // NSMutableDictionary* segment = [self.content.segments[indexPath.section] mutableCopy]; // if (email && email.length > 0) { // [segment setValue:email forKey:@"edit_content"]; // } else { // [segment removeObjectForKey:@"edit_content"]; // } // // NSMutableArray *arr = [self.content.segments mutableCopy]; // [arr replaceObjectAtIndex:indexPath.section withObject:segment]; // self.content.segments = arr; // // // 调用 tableView 的 beginUpdates 和 endUpdates,重新计算 cell 的高度 // [self.table beginUpdates]; // [self.table endUpdates]; // // // 防止在输入的时候超出屏幕区域 // CGRect frame = cell.frame; // if (CGRectGetMaxY(frame) > CGRectGetMaxY(self.table.bounds)) { // [self.table scrollRectToVisible:frame animated:NO]; // } //} // //- (void)commEditCell:(AMCommEditCell *)cell didBeginEditing:(UITextView *)textView { // self.editingCell = cell; // self.editingIndexPath = [self.table indexPathForCell:cell]; //} // //- (void)commEditCell:(AMCommEditCell *)cell didEndEditing:(UITextView *)textView { // self.editingCell = nil; // self.editingIndexPath = nil; //} // //#pragma mark - Contact Picker Delegate // //- (void)contactPickerDidCancel:(CNContactPickerViewController *)picker { // // self.contactSelectIndexPath = nil; //} // //- (void)contactPicker:(CNContactPickerViewController *)picker didSelectContact:(CNContact *)contact { // // [self handleSelectContact:contact]; // // self.contactSelectIndexPath = nil; //} // //- (void)contactPicker:(CNContactPickerViewController *)picker didSelectContacts:(NSArray *)contacts { // // for (CNContact *contact in contacts) { // [self handleSelectContact:contact]; // } // // self.contactSelectIndexPath = nil; //} // //- (void)contactPicker:(CNContactPickerViewController *)picker didSelectContactProperty:(CNContactProperty *)contactProperty { // // self.contactSelectIndexPath = nil; //} // //- (void)contactPicker:(CNContactPickerViewController *)picker didSelectContactProperties:(NSArray *)contactProperties { // // self.contactSelectIndexPath = nil; //} // //#pragma mark - Utils // //- (BOOL)validateEmail:(NSString *)email { // // NSString *emailRegex =@"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"; // // NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex]; // // return [emailTest evaluateWithObject:email]; //} // //- (void)handleSelectContact:(CNContact *)contact { // // NSArray *emailArr = [contact emailAddresses]; // for (CNLabeledValue *value in emailArr) { // if ([value.label isEqualToString:CNLabelWork]) { // [self appendCC:[NSString stringWithFormat:@"%@;",value.value] forIndexPath:self.contactSelectIndexPath]; // [self.table reloadRowsAtIndexPaths:@[self.contactSelectIndexPath] withRowAnimation:UITableViewRowAnimationNone]; // AMCommHeadCell *cell = [self.table cellForRowAtIndexPath:self.contactSelectIndexPath]; // [cell beginEditing]; // break; // } // } // //} // //- (void)appendCC:(NSString *)cc forIndexPath:(NSIndexPath *)indexPath { // if (indexPath == nil || cc == nil || cc.length == 0) { // return; // } // NSMutableDictionary* segment = [self.content.segments[indexPath.section] mutableCopy]; // NSString *oldCC = [segment objectForKey:@"cc"]; // if (oldCC == nil || oldCC.length == 0) { // oldCC = cc; // } else { // if ([[oldCC substringFromIndex:oldCC.length - 1] isEqualToString:@";"]) { // oldCC = [oldCC stringByAppendingString:cc]; // } else { // oldCC = [oldCC stringByAppendingString:[NSString stringWithFormat:@";%@",cc]]; // } // } // // [self cc:oldCC changedForIndexPath:indexPath]; //} // //- (void)cc:(NSString *)cc changedForIndexPath:(NSIndexPath *)indexPath { // if (indexPath == nil) { // return; // } // NSMutableDictionary* segment = [self.content.segments[indexPath.section] mutableCopy]; // if (cc && cc.length > 0) { // [segment setValue:cc forKey:@"cc"]; // } else { // [segment removeObjectForKey:@"cc"]; // } // // NSMutableArray *arr = [self.content.segments mutableCopy]; // [arr replaceObjectAtIndex:indexPath.section withObject:segment]; // self.content.segments = arr; //} // //#pragma mark - ShipMap Delegate // //- (void)shipMap:(AMShipMap *)shipMap tryToZoomIn:(BOOL)zoomIn { // // if (zoomIn) { // // NSArray *constraints = self.view.constraints; // NSLayoutConstraint *h_ratio_constraint = nil; // // for (NSLayoutConstraint *constraint in constraints) { // if (constraint.identifier && [constraint.identifier isEqualToString:@"ratio_constraint"]) { // h_ratio_constraint = constraint; // } // } // // if (h_ratio_constraint) { // [self.view removeConstraint:h_ratio_constraint]; // } // // NSLayoutConstraint *table_h_constraint = [NSLayoutConstraint constraintWithItem:self.table // attribute:NSLayoutAttributeHeight // relatedBy:NSLayoutRelationEqual // toItem:nil // attribute:NSLayoutAttributeNotAnAttribute // multiplier:0 // constant:0]; // table_h_constraint.identifier = @"table_height"; // [self.view addConstraint:table_h_constraint]; // // } else { // // NSArray *constraints = self.view.constraints; // NSLayoutConstraint *h_constraint = nil; // // for (NSLayoutConstraint *constraint in constraints) { // if (constraint.identifier && [constraint.identifier isEqualToString:@"table_height"]) { // h_constraint = constraint; // } // } // // if (h_constraint) { // [self.view removeConstraint:h_constraint]; // } // // float h_ratio = 0.5; // NSLayoutConstraint *h_ratio_constraint = [NSLayoutConstraint constraintWithItem:shipMap // attribute:NSLayoutAttributeHeight // relatedBy:NSLayoutRelationEqual // toItem:self.table // attribute:NSLayoutAttributeHeight // multiplier:h_ratio // constant:0]; // h_ratio_constraint.identifier = @"ratio_constraint"; // // [self.view addConstraint:h_ratio_constraint]; // } // // // [self.view layoutIfNeeded]; //} @end