DetailPageViewController.m 93 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416
  1. //
  2. // DetailPageViewController.m
  3. // Apex Mobile
  4. //
  5. // Created by Ray on 14-3-8.
  6. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "DetailPageViewController.h"
  9. //#import "AMShipMap.h"
  10. #define DEF_CELL_HEIGHT 44
  11. #define DEF_TABLE_HEIGHT 44
  12. #define LINE_WIDTH 0
  13. #define CELL_MARGIN 15
  14. #define LIST_VMARGIN 15
  15. #define LABEL_MARGIN 0
  16. #define NEW_MAPCELL_MARGIN 8
  17. #import "TabBarController.h"
  18. //#import "DetailCellTracking.h"
  19. #import <QuickLook/QuickLook.h>
  20. #import "DetailCellKVNew.h"
  21. #import "DetailCellContainer.h"
  22. #import "DetailCellContainerCA.h"
  23. #import "MyQLPreviewController.h"
  24. #import "LPShareActivity.h"
  25. #import "RADataProvider.h"
  26. //#import "AMCommEditCell.h"
  27. //#import "AMCommHeadCell.h"
  28. //#import "AMCommContentCell.h"
  29. //#import <Contacts/Contacts.h>
  30. //#import <ContactsUI/ContactsUI.h>
  31. //#define COMM_ID_HEAD @"COMM_ID_HEAD"
  32. //#define COMM_ID_CONTENT @"COMM_ID_CONTENT"
  33. //#define COMM_ID_EDIT @"COMM_ID_EDIT"
  34. @interface DetailHUD : UIView
  35. @property (nonatomic,strong) UILabel *msgLb;
  36. @end
  37. @implementation DetailHUD
  38. + (void)show:(NSString *)msg inView:(UIView *)view {
  39. if (!msg) {
  40. return;
  41. }
  42. DetailHUD *hud = [[DetailHUD alloc] initWithFrame:CGRectZero];
  43. hud.backgroundColor = [UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:0.9];
  44. hud.msgLb.text = msg;
  45. [hud layoutSize];
  46. for (UIView *sub in view.subviews) {
  47. if ([sub isKindOfClass:self]) {
  48. sub.hidden = YES;
  49. }
  50. }
  51. [view addSubview:hud];
  52. [hud performSelector:@selector(hide) withObject:nil afterDelay:3.0f];
  53. }
  54. - (UILabel *)msgLb {
  55. if (!_msgLb) {
  56. _msgLb = [[UILabel alloc] initWithFrame:CGRectZero];
  57. _msgLb.textColor = [UIColor whiteColor];
  58. _msgLb.font = [UIFont systemFontOfSize:14.0f];
  59. [self addSubview:_msgLb];
  60. }
  61. return _msgLb;
  62. }
  63. - (void)layoutSize {
  64. [self.msgLb sizeToFit];
  65. CGSize size = self.msgLb.bounds.size;
  66. CGFloat height = size.height + 20;
  67. CGFloat width = size.width + 20;
  68. if (height < 30) {
  69. height = 30;
  70. }
  71. if (width < 30) {
  72. width = 30;
  73. }
  74. self.msgLb.center = CGPointMake(width * 0.5, height * 0.5);
  75. self.bounds = CGRectMake(0, 0, width, height);
  76. self.layer.cornerRadius = 5.0f;
  77. self.layer.masksToBounds = YES;
  78. }
  79. - (void)willMoveToSuperview:(UIView *)newSuperview {
  80. [super willMoveToSuperview:newSuperview];
  81. if (newSuperview) {
  82. self.center = CGPointMake(newSuperview.bounds.size.width * 0.5, newSuperview.bounds.size.height * 0.5);
  83. }
  84. }
  85. - (void)layoutSubviews {
  86. [super layoutSubviews];
  87. if (self.superview) {
  88. self.center = CGPointMake(self.superview.bounds.size.width * 0.5, self.superview.bounds.size.height * 0.5);
  89. }
  90. }
  91. - (void)hide {
  92. [self removeFromSuperview];
  93. }
  94. @end
  95. @interface DetailPageViewController () <QLPreviewControllerDataSource,QLPreviewControllerDelegate,DetailKVCellTapDelegate>
  96. @property (nonatomic,strong) MyQLPreviewController *quickLook;
  97. @property (nonatomic,copy) NSString *documentPath;
  98. @property (nonatomic,copy) NSString *email;
  99. @property (nonatomic,copy) NSString *email_subject;
  100. @property (nonatomic,copy) NSString *email_content;
  101. //@property (nonatomic,strong) IBOutlet AMShipMap *shipMap;
  102. @property (nonatomic,weak) UITableViewCell *editingCell;
  103. @property (nonatomic,strong) NSIndexPath *editingIndexPath;
  104. @property (nonatomic,strong) NSIndexPath *contactSelectIndexPath;
  105. @property (nonatomic,weak) UITapGestureRecognizer *tap;
  106. @property (nonatomic,assign) BOOL showKeyboard;
  107. @property (nonatomic,strong) NSIndexPath *containerSelectedIndexPath;
  108. @end
  109. @implementation DetailPageViewController
  110. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  111. {
  112. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  113. if (self) {
  114. // Custom initialization
  115. }
  116. return self;
  117. }
  118. -(void)changeCell
  119. {
  120. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  121. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"refreshing"];
  122. [self performSelector:@selector(ReloadData) withObject:nil afterDelay:1];
  123. DebugLog(@"refresh!!!!!!!!");
  124. }
  125. -(void)ReloadData
  126. {
  127. // Count ++ ;
  128. // [mytabelview reloadData];
  129. [self loadpage];
  130. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  131. [reF endRefreshing];
  132. }
  133. - (void)viewDidLoad
  134. {
  135. [super viewDidLoad];
  136. // self.webviewoprationQueue = [[NSOperationQueue alloc] init];
  137. // self.webviewoprationQueue.maxConcurrentOperationCount = 1;
  138. UIRefreshControl *ref = [[UIRefreshControl alloc]init];
  139. ref.tag = 200 ;
  140. ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"drag to refresh"];
  141. ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  142. // ref.hidden = true;
  143. [ref addTarget:self action:@selector(changeCell) forControlEvents:UIControlEventValueChanged];
  144. [self.table addSubview:ref];
  145. if(self.tabBarController.tabBar.hidden==true)
  146. {
  147. CGRect frame = self.table.frame;
  148. frame.size.height +=40;
  149. self.table.frame=frame;
  150. }
  151. // self.view.backgroundColor= [UIColor whiteColor];
  152. [self loadpage];
  153. // Do any additional setup after loading the view.
  154. UIBarButtonItem *previewMenuBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"ic_more_dot"] style:UIBarButtonItemStylePlain target:self action:@selector(quickLookMenuClick:)];
  155. self.quickLook.navigationItem.rightBarButtonItem = previewMenuBtn;
  156. // [self configureMap];
  157. [self configureTableView];
  158. }
  159. - (void)viewWillAppear:(BOOL)animated {
  160. [super viewWillAppear:animated];
  161. NSString *action_type = [self.params objectForKey:@"action_type"];
  162. // if ([action_type isEqualToString:@"Detail"]) { // 避免Tap与Tacking中Cell点击冲突
  163. // [self startListenKeyboard];
  164. // }
  165. //
  166. // if (self.shipMap) {
  167. // [self.shipMap shipMapWillAppear];
  168. // }
  169. }
  170. - (void)viewWillDisappear:(BOOL)animated {
  171. [super viewWillDisappear:animated];
  172. // [self stopListenKeyboard];
  173. // if (self.shipMap) {
  174. // [self.shipMap shipMapWillDisappear];
  175. // }
  176. }
  177. - (void)configureTableView {
  178. // [self.table registerNib:[UINib nibWithNibName:@"AMCommHeadCell" bundle:nil] forCellReuseIdentifier:COMM_ID_HEAD];
  179. // [self.table registerNib:[UINib nibWithNibName:@"AMCommContentCell" bundle:nil] forCellReuseIdentifier:COMM_ID_CONTENT];
  180. // [self.table registerNib:[UINib nibWithNibName:@"AMCommEditCell" bundle:nil] forCellReuseIdentifier:COMM_ID_EDIT];
  181. //
  182. }
  183. //- (void)configureMap {
  184. //
  185. // if (!self.showMap) {
  186. //
  187. // NSArray *constraints = [[self.view constraints] mutableCopy];
  188. // // 删除Table与Map相关约束
  189. // for (NSLayoutConstraint *constaint in constraints) {
  190. // if ([constaint.identifier isEqualToString:@"top_constraint"]) {
  191. // [self.view removeConstraint:constaint];
  192. // } else if ([constaint.identifier isEqualToString:@"ratio_constraint"]) {
  193. // [self.view removeConstraint:constaint];
  194. // }
  195. // }
  196. //
  197. //// // 移除地图
  198. //// [self.shipMap removeFromSuperview];
  199. //// self.shipMap = nil;
  200. //
  201. // // 设置新约束
  202. // NSLayoutConstraint *top = [NSLayoutConstraint constraintWithItem:self.table
  203. // attribute:NSLayoutAttributeTop
  204. // relatedBy:NSLayoutRelationEqual
  205. // toItem:self.topLayoutGuide
  206. // attribute:NSLayoutAttributeBottom
  207. // multiplier:1.0
  208. // constant:0];
  209. // [self.view addConstraint:top];
  210. //
  211. //
  212. //
  213. // [self.view layoutIfNeeded];
  214. // } else {
  215. // self.shipMap.showCurrent = YES;
  216. // self.shipMap.showPoe = YES;
  217. // self.shipMap.showPol = YES;
  218. // self.shipMap.showPod = YES;
  219. // self.shipMap.showPor = YES;
  220. // self.shipMap.showOrigin = YES;
  221. // self.shipMap.showDestination = YES;
  222. //
  223. // self.shipMap.delegate = self;
  224. // }
  225. //
  226. //}
  227. - (void)saveDocumentClick:(id)sender {
  228. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  229. NSString *path = [paths objectAtIndex:0];
  230. NSString *filePath = [path stringByAppendingPathComponent:[self.documentPath lastPathComponent]];
  231. NSError *err;
  232. if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
  233. [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
  234. }
  235. [[NSFileManager defaultManager] moveItemAtPath:self.documentPath toPath:filePath error:&err];
  236. UIAlertController *alertVC;
  237. UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  238. }];
  239. if (err) {
  240. alertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"save document failed:\n%@",err.localizedDescription] preferredStyle:UIAlertControllerStyleAlert];
  241. } else {
  242. alertVC = [UIAlertController alertControllerWithTitle:nil message:@"Document Saved" preferredStyle:UIAlertControllerStyleAlert];
  243. }
  244. [alertVC addAction:action];
  245. [self presentViewController:alertVC animated:YES completion:nil];
  246. }
  247. - (void)didReceiveMemoryWarning
  248. {
  249. [super didReceiveMemoryWarning];
  250. // Dispose of any resources that can be recreated.
  251. }
  252. -(void) loadpage
  253. {
  254. // [self.params setValue:[NSString stringWithFormat:@"%d",self.offset] forKey:@"offset"];
  255. // self.prepageButton.enabled=false;
  256. // self.nextpageButton.enabled=false;
  257. self.mum.center = self.view.center;
  258. __weak typeof(self) weakSelf = self;
  259. NSTimeInterval animationDuration = 0.30f;
  260. [UIView beginAnimations:@"ResizeView" context:nil];
  261. [UIView setAnimationDuration:animationDuration];
  262. self.mum.hidden = false;
  263. self.table.hidden = true;
  264. [UIView commitAnimations];
  265. // if (self.showMap) {
  266. // [self.params setObject:@(YES) forKey:@"request_location"];
  267. // }
  268. // if ([[self.params objectForKey:@"action_type"] isEqualToString:@"Detail"]) {
  269. // [self.params setObject:@(YES) forKey:@"request_communication"];
  270. // }
  271. //
  272. [RADataProvider TabDetail:self.params completionHandler:^(NSMutableDictionary *result) {
  273. // ;
  274. self.content=[RADataProvider json2DetailContent:result];
  275. NSTimeInterval animationDuration = 0.30f;
  276. [UIView beginAnimations:@"ResizeView" context:nil];
  277. [UIView setAnimationDuration:animationDuration];
  278. self.mum.hidden = true;
  279. if(self.content.result_code!=RESULT_TRUE)
  280. {
  281. self.table.hidden =false;
  282. [self.table reloadData];
  283. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle: @"Warning"
  284. message: self.content.err_msg
  285. preferredStyle: UIAlertControllerStyleAlert];
  286. UIAlertAction *action_back = [UIAlertAction actionWithTitle:@"Back" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  287. [weakSelf.navigationController popViewControllerAnimated:false];
  288. }];
  289. UIAlertAction *action_reload = [UIAlertAction actionWithTitle:@"Reload" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  290. [weakSelf ReloadData];
  291. }];
  292. [alertVC addAction:action_back];
  293. [alertVC addAction:action_reload];
  294. [weakSelf presentViewController:alertVC animated:YES completion:nil];
  295. }
  296. else
  297. if([self.content get_segmentcount]==0)
  298. {
  299. self.table.hidden =true;
  300. self.norecordLabel.hidden=false;
  301. if(self.tabBarController.childViewControllers.count==1)
  302. {
  303. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle: @"Warning"
  304. message: @"No Search Result."
  305. preferredStyle: UIAlertControllerStyleAlert];
  306. UIAlertAction *action = [UIAlertAction actionWithTitle:@"Back" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  307. [weakSelf.navigationController popViewControllerAnimated:false];
  308. }];
  309. [alertVC addAction:action];
  310. [weakSelf presentViewController:alertVC animated:YES completion:nil];
  311. }
  312. }
  313. else
  314. {
  315. self.page_menu = result[@"page_menu"];
  316. self.table.hidden =false;
  317. [self.table reloadData];
  318. self.email = [self.content.originContent objectForKey:@"email"];
  319. self.email_subject = [self.content.originContent objectForKey:@"email_subject"];
  320. self.email_content = [self.content.originContent objectForKey:@"email_content"];
  321. }
  322. [UIView commitAnimations];
  323. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  324. // bool autologin =[defaults boolForKey:@"autologin"];
  325. // if(!autologin)
  326. // {
  327. // TabBarController * viewController =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginTabBar"];
  328. // [self presentViewController:viewController animated:YES completion:^{
  329. //
  330. // }];
  331. // }
  332. // 设置默认选中第一个Container
  333. for (NSInteger i = 0; i < self.content.segments.count; i++) {
  334. NSMutableDictionary* segment = [self.content.segments[i] mutableCopy];
  335. NSString* type =[segment valueForKey:@"_type"];
  336. // if([type isEqualToString:@"tracking"]) {
  337. // NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:i];
  338. // [self.table selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
  339. // [self tableView:self.table didSelectRowAtIndexPath:indexPath];
  340. // break;
  341. // }
  342. }
  343. }];
  344. return;
  345. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  346. //
  347. // self.content=[RANetwork get_detailcontent:self.params];
  348. //
  349. //
  350. // // PageData* pageData=nil;
  351. // // if(self.recordCount==-1)
  352. // // self.recordCount=[RANetwork get_recordcount: self.params ];
  353. // // if(self.recordCount>0)
  354. // // {
  355. // // self.pageData=[RANetwork get_pagedata:self.params];
  356. // // // self.pageData=[RANetwork]
  357. // // }
  358. // //
  359. // dispatch_async(dispatch_get_main_queue(), ^{
  360. //
  361. //
  362. // NSTimeInterval animationDuration = 0.30f;
  363. // [UIView beginAnimations:@"ResizeView" context:nil];
  364. // [UIView setAnimationDuration:animationDuration];
  365. //
  366. //
  367. // self.mum.hidden = true;
  368. // if(self.content.result_code!=RESULT_TRUE)
  369. // {
  370. // self.table.hidden =false;
  371. // [self.table reloadData];
  372. //
  373. // }
  374. // else
  375. // if([self.content get_segmentcount]==0)
  376. // {
  377. //
  378. //
  379. // self.table.hidden =true;
  380. // self.norecordLabel.hidden=false;
  381. //
  382. // if(self.tabBarController.childViewControllers.count==1)
  383. // {
  384. // UIAlertController *alertVC = [UIAlertController alertControllerWithTitle: @"Warning"
  385. // message: @"No Search Result."
  386. // preferredStyle: UIAlertControllerStyleAlert];
  387. // UIAlertAction *action = [UIAlertAction actionWithTitle:@"Back" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  388. // [weakSelf.navigationController popViewControllerAnimated:false];
  389. // }];
  390. // [alertVC addAction:action];
  391. // [weakSelf presentViewController:alertVC animated:YES completion:nil];
  392. //
  393. // }
  394. //
  395. //
  396. //
  397. // }
  398. // else
  399. // {
  400. // self.table.hidden =false;
  401. // [self.table reloadData];
  402. //
  403. // self.email = [self.content.originContent objectForKey:@"email"];
  404. // self.email_subject = [self.content.originContent objectForKey:@"email_subject"];
  405. // self.email_content = [self.content.originContent objectForKey:@"email_content"];
  406. // }
  407. // [UIView commitAnimations];
  408. //
  409. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  410. // bool autologin =[defaults boolForKey:@"autologin"];
  411. // if(!autologin)
  412. // {
  413. // TabBarController * viewController =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginTabBar"];
  414. // [self presentViewController:viewController animated:YES completion:^{
  415. //
  416. // }];
  417. // }
  418. // // 设置默认选中第一个Container
  419. // for (NSInteger i = 0; i < self.content.segments.count; i++) {
  420. //
  421. // NSMutableDictionary* segment = [self.content.segments[i] mutableCopy];
  422. // NSString* type =[segment valueForKey:@"_type"];
  423. //
  424. // if([type isEqualToString:@"tracking"]) {
  425. // NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:i];
  426. // [self.table selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
  427. // [self tableView:self.table didSelectRowAtIndexPath:indexPath];
  428. // break;
  429. // }
  430. // }
  431. //
  432. // // [self.table setNeedsDisplay];
  433. // // if(self.recordCount<2000)
  434. // // self.countView.title = [NSString stringWithFormat:@"%d records",self.recordCount];
  435. // // else
  436. // // self.countView.title = @"2000+ records";
  437. // //
  438. // // if(self.offset<self.pageData.get_count)
  439. // // self.prepageButton.enabled=false;
  440. // // else
  441. // // self.prepageButton.enabled=true;
  442. // // if(self.offset+self.pageData.get_count>=self.recordCount)
  443. // // self.nextpageButton.enabled=false;
  444. // // else
  445. // // self.nextpageButton.enabled=true;
  446. // // [self.grid initgrid :self.pageData];
  447. //
  448. //
  449. // });
  450. // });
  451. }
  452. //- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
  453. //{
  454. //// [self.table beginUpdates];
  455. // [self.table reloadData];
  456. //// [self.table endUpdates];
  457. //
  458. //}
  459. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
  460. __weak typeof(self) weakSelf = self;
  461. [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
  462. // 动画前
  463. } completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
  464. // 动画后
  465. [weakSelf.table reloadData];
  466. }];
  467. [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
  468. }
  469. //// 是否支持屏幕旋转
  470. //- (BOOL)shouldAutorotate {
  471. //
  472. //
  473. // return YES;
  474. //}
  475. //// 支持的旋转方向
  476. //- (NSUInteger)supportedInterfaceOrientations {
  477. // return UIInterfaceOrientationLandscapeRight;//UIInterfaceOrientationMaskAllButUpsideDown;
  478. //}
  479. //// 一开始的屏幕旋转方向
  480. //- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
  481. // return UIInterfaceOrientationLandscapeRight;
  482. //}
  483. - (void)showDocument:(NSString *)url {
  484. __weak typeof(self) weakSelf = self;
  485. // show alert
  486. UIAlertController *alertController = [UIAlertController alertControllerWithTitle: nil
  487. message: @"loading..."
  488. preferredStyle: UIAlertControllerStyleAlert];
  489. UIViewController *customVC = [[UIViewController alloc] init];
  490. UIActivityIndicatorView* spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
  491. spinner.color = [UIColor darkGrayColor];
  492. [spinner startAnimating];
  493. [customVC.view addSubview:spinner];
  494. [customVC.view addConstraint:[NSLayoutConstraint
  495. constraintWithItem: spinner
  496. attribute:NSLayoutAttributeCenterX
  497. relatedBy:NSLayoutRelationEqual
  498. toItem:customVC.view
  499. attribute:NSLayoutAttributeCenterX
  500. multiplier:1.0f
  501. constant:0.0f]];
  502. [customVC.view addConstraint:[NSLayoutConstraint
  503. constraintWithItem: spinner
  504. attribute:NSLayoutAttributeCenterY
  505. relatedBy:NSLayoutRelationEqual
  506. toItem:customVC.view
  507. attribute:NSLayoutAttributeCenterY
  508. multiplier:1.0f
  509. constant:0.0f]];
  510. [alertController setValue:customVC forKey:@"contentViewController"];
  511. [self presentViewController: alertController animated: YES completion: nil];
  512. // NSString *cacheDir = NSTemporaryDirectory();
  513. [RADataProvider DownloadFile:nil url:url completionHandler:^(NSMutableDictionary *result) {
  514. // [RANetwork request_download:nil url:url err_record_url:nil offset:0 method:nil storein:cacheDir progressHandler:nil completionHandler:^(NSMutableDictionary *result) {
  515. weakSelf.documentPath = nil;
  516. [alertController dismissViewControllerAnimated:YES completion:^{
  517. if ([[result objectForKey:@"result"] intValue] == RESULT_TRUE) {
  518. NSString *cachePath = [result objectForKey:@"path"];
  519. weakSelf.documentPath = cachePath;
  520. if (cachePath) { // push 必须在completion中
  521. [weakSelf.navigationController pushViewController:weakSelf.quickLook animated:YES];
  522. }
  523. } else {
  524. NSString *msg = [result objectForKey:@"msg"];
  525. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle: @"Warning"
  526. message: msg
  527. preferredStyle: UIAlertControllerStyleAlert];
  528. UIAlertAction *action = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  529. }];
  530. [alertVC addAction:action];
  531. [weakSelf presentViewController:alertVC animated:YES completion:nil];
  532. }
  533. }];
  534. }];
  535. // [RANetwork request_download:nil url:url completionHandler:^(NSMutableDictionary *result) {
  536. //
  537. //
  538. // }];
  539. //
  540. // // download
  541. // dispatch_async(dispatch_get_global_queue(0, 0), ^{
  542. //
  543. // // NSArray *paths = NSSearchPathForDirectoriesInDomains(nstem, NSUserDomainMask, YES);
  544. // // NSString *documents = [paths objectAtIndex:0];
  545. // // NSString *cacheDir = [documents stringByAppendingPathComponent:[module_name stringByAppendingString:@"_download"]];
  546. //
  547. // NSString *cacheDir = NSTemporaryDirectory();
  548. //
  549. // if (![[NSFileManager defaultManager] fileExistsAtPath:cacheDir]) {
  550. // [[NSFileManager defaultManager] createDirectoryAtPath:cacheDir withIntermediateDirectories:NO attributes:nil error:nil];
  551. // }
  552. //
  553. // // NSString *path = [cacheDir stringByAppendingPathComponent:[NSUUID UUID].UUIDString];
  554. //
  555. //
  556. //
  557. // [RANetwork download_file:nil url:url toCachePath:cacheDir progressHandler:^(NSURLSessionTask *task, double progress) {
  558. //
  559. // DebugLog(@"download progress %f",progress);
  560. // } completionHandler:^(NSMutableDictionary *result) {
  561. //
  562. // dispatch_async(dispatch_get_main_queue(), ^{
  563. //
  564. // weakSelf.documentPath = nil;
  565. // [alertController dismissViewControllerAnimated:YES completion:^{
  566. //
  567. //
  568. // if ([[result objectForKey:@"result"] intValue] == RESULT_TRUE) {
  569. //
  570. // NSString *cachePath = [result objectForKey:@"path"];
  571. // weakSelf.documentPath = cachePath;
  572. //
  573. // if (cachePath) { // push 必须在completion中
  574. // [weakSelf.navigationController pushViewController:weakSelf.quickLook animated:YES];
  575. // }
  576. //
  577. // } else {
  578. //
  579. // NSString *msg = [result objectForKey:@"msg"];
  580. //
  581. // UIAlertController *alertVC = [UIAlertController alertControllerWithTitle: @"Warning"
  582. // message: msg
  583. // preferredStyle: UIAlertControllerStyleAlert];
  584. // UIAlertAction *action = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  585. //
  586. // }];
  587. // [alertVC addAction:action];
  588. // [weakSelf presentViewController:alertVC animated:YES completion:nil];
  589. // }
  590. //
  591. // }];
  592. //
  593. //
  594. // });
  595. //
  596. // DebugLog(@"download result %@",result);
  597. //
  598. // }];
  599. //
  600. //
  601. // });
  602. }
  603. #pragma mark - WKNavigationDelegate
  604. - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
  605. {
  606. NSLog(@"webview didFinishNavigation");
  607. UITableViewCell *cell = (UITableViewCell *)[[webView superview] superview];
  608. NSIndexPath *indexPath = [self.table indexPathForCell:cell];
  609. if(indexPath==nil)
  610. {//for ios7
  611. cell = (UITableViewCell *) webView.superview.superview.superview;
  612. indexPath = [self.table indexPathForCell:cell];
  613. }
  614. float height= [[self.content.webviewHeight valueForKey:[NSString stringWithFormat:@"%ld",(long)indexPath.section]] floatValue];
  615. if(height>0)
  616. return;
  617. [webView evaluateJavaScript:@"document.body.scrollHeight;" completionHandler:^(id _Nullable fitHeight,NSError * _Nullable error) {
  618. CGRect frame = webView.frame;
  619. frame.size.height = [fitHeight floatValue];
  620. //webView.frame = frame;
  621. [self.content.webviewHeight setObject:[NSString stringWithFormat:@"%f",frame.size.height/*webView.scrollView.contentSize.height*/] forKey:[NSString stringWithFormat:@"%ld",(long)indexPath.section]];
  622. DebugLog(@"webViewDidFinishLoad ^^^^^^^^^^^^^^^^^reloadRowsAtIndexPaths");
  623. if (![[self.table indexPathsForVisibleRows] containsObject:indexPath])
  624. {
  625. //cell 已无法显示。
  626. return;
  627. }
  628. dispatch_async(dispatch_get_main_queue(), ^{
  629. NSLog(@"reload tableview!!! %f",frame.size.height);
  630. // UI更新代码
  631. // [self.table reloadData];
  632. // [self.detailTable reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
  633. [self.table reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
  634. //[self.editorTable reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
  635. });
  636. }];
  637. }
  638. //禁止链接跳转
  639. - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
  640. NSLog(@"%s",__func__);
  641. NSLog(@"navigationAction = %@, \r!!!!!!!!!!!!!!!!!!!!!!\n request = %@",navigationAction,navigationAction.request.URL);
  642. if(navigationAction.navigationType != WKNavigationTypeLinkActivated)
  643. return decisionHandler(WKNavigationActionPolicyAllow);
  644. // NSString *currentURL =[webView.request.URL lastPathComponent];// [webView stringByEvaluatingJavaScriptFromString:@"document.title"];
  645. NSString* str = navigationAction.request.URL.absoluteString;
  646. if([str isEqualToString:@"about:blank"])
  647. return decisionHandler(WKNavigationActionPolicyAllow);;
  648. [self showDocument:navigationAction.request.URL.absoluteString];
  649. return decisionHandler(WKNavigationActionPolicyCancel);;
  650. }
  651. #pragma mark - Section Switch
  652. - (void)sectionSwitchClick:(UIButton *)sender {
  653. NSInteger section = sender.tag - 1020;
  654. NSMutableArray *segments = [self.content.segments mutableCopy];
  655. NSMutableDictionary* segment = [self.content.segments[section] mutableCopy];
  656. NSString* type =[segment valueForKey:@"_type"];
  657. // if([type isEqualToString:@"tracking"])
  658. // {
  659. // BOOL close = [[segment objectForKey:@"close"] boolValue];
  660. //
  661. // if (!close) {
  662. // close = YES;
  663. // } else {
  664. // close = NO;
  665. // }
  666. // [segment setValue:@(close) forKey:@"close"];
  667. // segments[section] = segment;
  668. // self.content.segments = segments;
  669. //// [self.table reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:UITableViewRowAnimationNone];
  670. // [self.table reloadData];
  671. // }
  672. }
  673. - (void)copyTap:(UITapGestureRecognizer *)tap {
  674. UILabel *lb = (UILabel *)tap.view;
  675. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  676. pasteboard.string = lb.text;
  677. [DetailHUD show:[NSString stringWithFormat:@"%@ Copied",lb.text] inView:self.view];
  678. }
  679. #pragma mark - Table view data source
  680. //
  681. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  682. //{
  683. // return 40;
  684. //}
  685. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  686. {
  687. DebugLog(@"heightForRowAtIndexPath");
  688. // float height = [self.content itemHeightAtIndexPath:indexPath];
  689. NSString* type = [self.content get_segmenttype:indexPath.section];
  690. if([type isEqualToString:@"table"])
  691. {
  692. // [self.content.webviewHeight setObject:[NSString stringWithFormat:@"%f",webView.frame.size.height] forKey:[NSString stringWithFormat:@"%d",webView.tag]];
  693. float height= [[self.content.webviewHeight valueForKey:[NSString stringWithFormat:@"%ld",(long)indexPath.section]] floatValue];
  694. if(height==0)
  695. height=DEF_TABLE_HEIGHT;
  696. // DebugLog(@"heightForRowAtIndexPath...............webview,hight = %f section=%ld",height,indexPath.section);
  697. //wait(1000);
  698. return height;
  699. }
  700. // else if([type isEqualToString:@"tracking"])
  701. // {
  702. // return 64;
  703. // }
  704. else if([type isEqualToString:@"container"])
  705. {
  706. return 100;
  707. }
  708. else if([type isEqualToString:@"container_ca"])
  709. {
  710. return 48;
  711. }
  712. else if([type isEqualToString:@"mapping"])
  713. {
  714. // NSString *CellIdentifier = @"detail_item_kvnew";
  715. // DetailCellKVNew *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  716. NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
  717. NSString* key =[item allKeys][0];
  718. // [cell.keyLabel sizeToFit];
  719. NSString* val=[item valueForKey:key];
  720. if([val isEqual:[NSNull null]])
  721. val=@"";
  722. // cell.keyLabel.text = key;
  723. // cell.valLabel.htmlText = val;
  724. // UILabel* l = [UILabel new];
  725. // l.text =@"Place_Of_Receipt";
  726. // CGSize size= [l sizeThatFits:CGSizeMake(116,MAXFLOAT)];
  727. float width = tableView.frame.size.width;
  728. // width-=CELL_MARGIN*2;
  729. CGSize constraintkey = CGSizeMake(width*0.4-2*NEW_MAPCELL_MARGIN, MAXFLOAT);//key label width is 40% cell width;
  730. CGSize constraintval = CGSizeMake(width*0.6-2*NEW_MAPCELL_MARGIN, MAXFLOAT);//val label width is 60% cell width;
  731. /*
  732. NSLineBreakByWordWrapping = 0, // Wrap at word boundaries, default
  733. NSLineBreakByCharWrapping, // Wrap at character boundaries
  734. NSLineBreakByClipping, // Simply clip
  735. NSLineBreakByTruncatingHead, // Truncate at head of line: "...wxyz"
  736. NSLineBreakByTruncatingTail,
  737. */
  738. UIFont * F1=[UIFont systemFontOfSize:13];
  739. UIFont * F2=[UIFont fontWithName:@".SFUIText-Bold" size:13];//[UIFont boldSystemFontOfSize:13];
  740. // [UILabel setFont:];
  741. MDHTMLLabel* keylabel = [MDHTMLLabel new];
  742. keylabel.font = F2;
  743. keylabel.numberOfLines = 0;
  744. keylabel.lineBreakMode = NSLineBreakByTruncatingTail;
  745. keylabel.frame = CGRectMake(0, 0, constraintkey.width, constraintkey.height);
  746. keylabel.text=key;
  747. CGSize calkeysize= [keylabel sizeThatFits:constraintkey];
  748. if([key isEqualToString:@"Place_Of_Delivery"])
  749. {
  750. // int abc=0;
  751. }
  752. // [keylabel sizeToFit];
  753. // CGRect r = keylabel.frame;
  754. MDHTMLLabel* vallabel = [MDHTMLLabel new];
  755. vallabel.font = F1;
  756. vallabel.numberOfLines = 0;
  757. vallabel.lineBreakMode = NSLineBreakByWordWrapping;
  758. vallabel.htmlText=val;
  759. vallabel.frame = CGRectMake(0, 0, constraintval.width, constraintval.height);
  760. CGSize calvalsize= [vallabel sizeThatFits:constraintval];
  761. float height = MAX(calkeysize.height,calvalsize.height)+NEW_MAPCELL_MARGIN*2;
  762. height = MAX(height+LINE_WIDTH, DEF_CELL_HEIGHT);
  763. return height;
  764. //
  765. // NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
  766. // NSString* key =[item allKeys][0];
  767. // // [cell.keyLabel sizeToFit];
  768. // NSString* val=[item valueForKey:key];
  769. // if([val isEqual:[NSNull null]])
  770. // val=@"";
  771. // if(val==nil)
  772. // val=@"";
  773. // if([val isEqualToString:@"null"])
  774. // val=@"";
  775. //
  776. //
  777. //
  778. // CGRect frame;
  779. // frame.size = constraintval;
  780. // frame.origin.x=0;
  781. // frame.origin.y=0;
  782. // RTLabel* rtlabel = [[RTLabel alloc] initWithFrame:frame];
  783. // [rtlabel setLineBreakMode: RTTextLineBreakModeWordWrapping];
  784. // // rtlabel.lineSpacing = 20.0;
  785. // [rtlabel setText: val];
  786. // CGSize sizeval=rtlabel.optimumSize;
  787. //
  788. //
  789. // CGSize sizekey = [key sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  790. // // CGSize sizeval = [val sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintval lineBreakMode:NSLineBreakByWordWrapping];
  791. // float height = MAX(sizekey.height,sizeval.height);
  792. // height = MAX(height+LINE_WIDTH, DEF_CELL_HEIGHT);
  793. //
  794. // /*
  795. // NSString *text = [items objectAtIndex:[indexPath row]];
  796. //
  797. // CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 20000.0f);
  798. //
  799. // CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
  800. //
  801. // CGFloat height = MAX(size.height, 44.0f);
  802. //
  803. // return height + (CELL_CONTENT_MARGIN * 2);
  804. // */
  805. // // NSString *CellIdentifier = @"detail_item_kv";
  806. // // DetailCellKV *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  807. // // NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
  808. // // cell.keyLabel.text=[item allKeys][0];
  809. // // [cell.keyLabel sizeToFit];
  810. // // cell.valLabel.text= [item valueForKey:cell.keyLabel.text];
  811. // // [cell.valLabel sizeToFit];
  812. // //
  813. // // return MAX(cell.keyLabel.frame.size.height,cell.valLabel.frame.size.height);
  814. // return height;
  815. }
  816. // else if ([type isEqualToString:@"communication"]) {
  817. // NSInteger rowCount = [self tableView:tableView numberOfRowsInSection:indexPath.section];
  818. // if (indexPath.row == 0) {
  819. // return 118.0f;
  820. // } else if (indexPath.row == rowCount - 1) {
  821. //
  822. // NSMutableDictionary* segment = [self.content.segments[indexPath.section] mutableCopy];
  823. // NSString *edit_content = [segment objectForKey:@"edit_content"];
  824. //
  825. // CGFloat h = 40.0f; // 输入框高度,最小40
  826. // if (edit_content && edit_content.length > 0) {
  827. //
  828. // AMCommEditCell *cell = [[[NSBundle mainBundle] loadNibNamed:@"AMCommEditCell" owner:nil options:nil] objectAtIndex:0];
  829. //
  830. // h = [cell heightForContent:edit_content withTableWidth:CGRectGetWidth(tableView.bounds)];
  831. //
  832. // if (h < 40.0f) {
  833. // h = 40.0f;
  834. // } else if (h > 100.0f) { // 输入框高度,最大100
  835. // h = 100.0f;
  836. // }
  837. //
  838. //
  839. // } else {
  840. // h = 40.0f;
  841. // }
  842. //
  843. // return 50.0f + h;
  844. // } else {
  845. //
  846. // NSMutableDictionary* segment = [self.content.segments[indexPath.section] mutableCopy];
  847. // NSString *itemKey = [NSString stringWithFormat:@"item%ld",indexPath.row - 1];
  848. // NSDictionary *item = [[segment objectForKey:itemKey] mutableCopy];
  849. //
  850. // CGFloat height = [[item objectForKey:@"content_height"] floatValue];
  851. // if (height <= 0) {
  852. //
  853. // NSString *content = [item objectForKey:@"msg"];
  854. //
  855. // if (content && content.length > 0) {
  856. // NSDictionary *attribute = @{NSFontAttributeName: [UIFont systemFontOfSize:14.0f]};
  857. //
  858. // CGSize resSize = [content boundingRectWithSize:CGSizeMake(CGRectGetWidth(tableView.bounds) - 11, MAXFLOAT)
  859. // options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading)
  860. // attributes:attribute
  861. // context:nil].size;
  862. // height = resSize.height;
  863. // } else {
  864. // height = 0;
  865. // }
  866. //
  867. // [item setValue:@(height) forKey:@"content_height"];
  868. // [segment setObject:item forKey:itemKey];
  869. //
  870. // NSMutableArray *arr = [self.content.segments mutableCopy];
  871. // [arr replaceObjectAtIndex:indexPath.section withObject:segment];
  872. // self.content.segments = arr;
  873. // }
  874. //
  875. // return 71.5 + height;
  876. // }
  877. // }
  878. else if([type isEqualToString:@"log"])
  879. {
  880. DebugLog(@"cellForRowAtIndexPath =====> list");
  881. float width = tableView.frame.size.width;
  882. width-=CELL_MARGIN*2;
  883. CGSize constraintval = CGSizeMake(width, 20000.0f);//val label width is 60% cell width;
  884. NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
  885. NSString* text=item[@"text"];
  886. if([text isEqual:[NSNull null]])
  887. text=@"";
  888. if(text==nil)
  889. text=@"";
  890. if([text isEqualToString:@"null"])
  891. text=@"";
  892. // CGRect frame;
  893. // frame.size = constraintval;
  894. // frame.origin.x=0;
  895. // frame.origin.y=0;
  896. // CGSize sizeText = [text sizeWithFont:[UIFont systemFontOfSize:13.0] constrainedToSize:constraintval lineBreakMode:NSLineBreakByWordWrapping];
  897. // CGSize sizeval = [val sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintval lineBreakMode:NSLineBreakByWordWrapping];
  898. CGSize sizeText = [text boundingRectWithSize:constraintval options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading) attributes: @{NSFontAttributeName: [UIFont systemFontOfSize:13.0]} context:nil].size;
  899. // UILabel* label = [UILabel new];
  900. // label.frame= CGRectMake(0, 0, width, 2000.0f);
  901. //
  902. // label.font =[UIFont systemFontOfSize:13.0];
  903. //
  904. // CGSize bestsize=[label sizeThatFits:constraintval];
  905. float height = sizeText.height;
  906. height = MAX(height+LINE_WIDTH+LIST_VMARGIN, DEF_CELL_HEIGHT);
  907. return ceilf(height);
  908. }
  909. else
  910. {
  911. DebugLog(@"cellForRowAtIndexPath =====> list");
  912. float width = tableView.frame.size.width;
  913. width-=CELL_MARGIN*2;
  914. CGSize constraintval = CGSizeMake(width, 20000.0f);//val label width is 60% cell width;
  915. NSDictionary* item = self.content.segments[indexPath.section];
  916. NSString* text=[item valueForKey:[NSString stringWithFormat:@"line%ld",(long)indexPath.row]];
  917. if([text isEqual:[NSNull null]])
  918. text=@"";
  919. if(text==nil)
  920. text=@"";
  921. if([text isEqualToString:@"null"])
  922. text=@"";
  923. // CGRect frame;
  924. // frame.size = constraintval;
  925. // frame.origin.x=0;
  926. // frame.origin.y=0;
  927. // CGSize sizeText = [text sizeWithFont:[UIFont systemFontOfSize:13.0] constrainedToSize:constraintval lineBreakMode:NSLineBreakByWordWrapping];
  928. // CGSize sizeval = [val sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintval lineBreakMode:NSLineBreakByWordWrapping];
  929. CGSize sizeText = [text boundingRectWithSize:constraintval options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading) attributes: @{NSFontAttributeName: [UIFont systemFontOfSize:13.0]} context:nil].size;
  930. float height = sizeText.height;
  931. height = MAX(height+LINE_WIDTH+LIST_VMARGIN, DEF_CELL_HEIGHT);
  932. return ceilf(height);
  933. }
  934. // return height;
  935. }
  936. //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  937. //{
  938. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)];
  939. // myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  940. // UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 90, 22)];
  941. // titleLabel.textColor=[UIColor whiteColor];
  942. // titleLabel.backgroundColor = [UIColor clearColor];
  943. // titleLabel.text =[self.content get_segmentname:section];
  944. // [titleLabel sizeToFit];
  945. // [myView addSubview:titleLabel];
  946. //
  947. // return myView;
  948. //}
  949. //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  950. //{
  951. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)];
  952. // myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  953. //// UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 90, 22)];
  954. //// titleLabel.textColor=[UIColor whiteColor];
  955. //// titleLabel.backgroundColor = [UIColor grayColor];
  956. //// titleLabel.text =[self.content get_segmentname:section];
  957. //// [titleLabel sizeToFit];
  958. //// [myView addSubview:titleLabel];
  959. //
  960. // return myView;
  961. //}
  962. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  963. {
  964. DebugLog(@"numberOfSectionsInTableView=%ld",[self.content get_segmentcount]);
  965. return [self.content get_segmentcount];
  966. }
  967. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  968. {
  969. DebugLog(@"numberOfRowsInSection=%d",[self.content get_itemcount:section]);
  970. NSMutableDictionary* segment = [self.content.segments[section] mutableCopy];
  971. NSString* type =[segment valueForKey:@"_type"];
  972. if ([type isEqualToString:@"communication"]) {
  973. return [self.content get_itemcount:section] + 2;
  974. } else {
  975. return [self.content get_itemcount:section];
  976. }
  977. }
  978. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  979. DebugLog(@"titleForHeaderInSection=%@",[self.content get_segmentname:section]);
  980. return [self.content get_segmentname:section];
  981. }
  982. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  983. NSMutableDictionary* segment = [self.content.segments[section] mutableCopy];
  984. NSString* type =[segment valueForKey:@"_type"];
  985. CGFloat w = tableView.frame.size.width;
  986. UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, w, 30)];
  987. UILabel *titleLb = [[UILabel alloc] initWithFrame:CGRectMake(5, 0, w - 100, 30)];
  988. titleLb.font = [UIFont systemFontOfSize:15.0f];
  989. titleLb.textColor = APGRAYCOLOR;
  990. titleLb.text = [self tableView:tableView titleForHeaderInSection:section];
  991. [header addSubview:titleLb];
  992. // if([type isEqualToString:@"tracking"])
  993. // {
  994. // BOOL close = [[segment objectForKey:@"close"] boolValue];
  995. // NSString *title = @"Show";
  996. // if (!close) {
  997. // title = @"Hide";
  998. // } else {
  999. // title = @"Show";
  1000. // }
  1001. //
  1002. // UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  1003. // btn.frame = CGRectMake(w - 70, 0, 60, 30);
  1004. // btn.tag = 1020 + section;
  1005. // [btn setTitle:title forState:UIControlStateNormal];
  1006. // [btn setTitleColor:APGRAYCOLOR forState:UIControlStateNormal];
  1007. // [btn addTarget:self action:@selector(sectionSwitchClick:) forControlEvents:UIControlEventTouchUpInside];
  1008. //
  1009. // [header addSubview:btn];
  1010. //
  1011. // // Tap Copy
  1012. // UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(copyTap:)];
  1013. // tapGesture.numberOfTapsRequired = 2;
  1014. // [titleLb addGestureRecognizer:tapGesture];
  1015. // titleLb.userInteractionEnabled = YES;
  1016. // }
  1017. return header;
  1018. }
  1019. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  1020. {
  1021. return 30;
  1022. }
  1023. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  1024. {
  1025. return 0.0001;
  1026. }
  1027. //- (UIImage *) imageWithTintColor:(UIImage*)source Color:(UIColor *)tintColor blendMode:(CGBlendMode)blendMode {
  1028. // //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.
  1029. // UIGraphicsBeginImageContextWithOptions(source.size, NO, 0.0f); [tintColor setFill];
  1030. // CGRect bounds = CGRectMake(0, 0, source.size.width, source.size.height); UIRectFill(bounds);
  1031. // //Draw the tinted image in context
  1032. // [source drawInRect:bounds blendMode:blendMode alpha:1.0f];
  1033. // if (blendMode != kCGBlendModeDestinationIn)
  1034. // {
  1035. // [source drawInRect:bounds blendMode:kCGBlendModeDestinationIn alpha:1.0f];
  1036. // }
  1037. // UIImage *tintedImage = UIGraphicsGetImageFromCurrentImageContext();
  1038. // UIGraphicsEndImageContext();
  1039. // return tintedImage;
  1040. //}
  1041. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  1042. {
  1043. // NSString *CellIdentifier = @"testcell";
  1044. // return [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1045. NSString* type = [self.content get_segmenttype:indexPath.section];
  1046. if([type isEqualToString:@"table"])
  1047. {
  1048. DebugLog(@"cellForRowAtIndexPath =====> table");
  1049. static NSString *CellIdentifier = @"detail_item_web";
  1050. DetailCellWeb *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1051. NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
  1052. NSString* tablecontent = [item valueForKey:@"content"];
  1053. cell.webView.tag = indexPath.section;
  1054. // cell.webView.scrollView.contentSize.height = 0;
  1055. cell.webView.scrollView.bounces=NO;
  1056. cell.webView.scrollView.directionalLockEnabled = true;
  1057. CGSize size= cell.webView.scrollView.contentSize;
  1058. size.height=10;
  1059. cell.webView.scrollView.contentSize=size;
  1060. cell.webView.navigationDelegate=self;
  1061. // nsstring* c = [NSString stringwith]
  1062. // NSString *filePath = [[NSBundle mainBundle]pathForResource:@"about" ofType:@"htm"];
  1063. // NSString *htmlString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
  1064. [cell.webView loadHTMLString:tablecontent baseURL:nil];
  1065. // dispatch_async(dispatch_get_main_queue(), ^{
  1066. //
  1067. // wait(5000);
  1068. // DebugLog(@"!!!!!!!!!!!!!!!!!!!!!!!!!!!webview section=%ld height=%f",indexPath.section,cell.webView.scrollView.contentSize.height);
  1069. //
  1070. //// DebugLog(@"url:%@", [self.webView stringByEvaluatingJavaScriptFromString:@"window.location.href;"]); // shows google.com instead of about:blank
  1071. // });
  1072. // CGRect rect = cell.webView.frame;
  1073. // [self.content set_itemheight:cell.webView.frame.size.height AtIndexPath:indexPath];
  1074. // [cell.webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:filePath]];
  1075. return cell;
  1076. }
  1077. // else if([type isEqualToString:@"tracking"])
  1078. // {
  1079. // DebugLog(@"cellForRowAtIndexPath =====> table");
  1080. //
  1081. // static NSString *CellIdentifier = @"detail_item_tracking";
  1082. //
  1083. // DetailCellTracking *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1084. // NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
  1085. //
  1086. // if(indexPath.row==0)
  1087. // {
  1088. // cell.trackingIcon.tintColor=UIColorFromRGB(0x1e7ffb);
  1089. // cell.trackingIcon.image = [[UIImage imageNamed:item[@"icon"]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  1090. // }
  1091. // else
  1092. // {
  1093. // cell.trackingIcon.tintColor=[UIColor grayColor];
  1094. // cell.trackingIcon.image = [[UIImage imageNamed:item[@"icon"]] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
  1095. // }
  1096. //
  1097. //
  1098. // cell.trackingMsg.text=item[@"msg"];
  1099. //// NSString* tablecontent = [item valueForKey:@"content"];
  1100. //// cell.webView.tag = indexPath.section;
  1101. //// // cell.webView.scrollView.contentSize.height = 0;
  1102. //// cell.webView.scrollView.bounces=NO;
  1103. //// cell.webView.scrollView.directionalLockEnabled = true;
  1104. //// CGSize size= cell.webView.scrollView.contentSize;
  1105. //// size.height=10;
  1106. //// cell.webView.scrollView.contentSize=size;
  1107. ////
  1108. ////
  1109. //// [cell.webView loadHTMLString:tablecontent baseURL:nil];
  1110. //
  1111. // return cell;
  1112. // }
  1113. else if([type isEqualToString:@"container"])
  1114. {
  1115. NSString *CellIdentifier = @"detail_item_container";
  1116. DetailCellContainer *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1117. NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
  1118. cell.labelCMB.text = item[@"cmb"];
  1119. cell.labelQTY.text = item[@"qty"];
  1120. cell.labelWeight.text = item[@"weight"];
  1121. cell.labelSize.text = item[@"size"];
  1122. cell.labelContainerNo.text = item[@"container#"];
  1123. cell.labelService.text=item[@"service"];
  1124. cell.labelSealNo.text=item[@"seal_no"];
  1125. //cell.tapDelegate = self;
  1126. // UIView * lineview = [[LineView alloc] initWithFrame:cell.contentView.frame];
  1127. // lineview.userInteractionEnabled = NO;// 不设为NO会屏蔽cell的点击事件
  1128. // lineview.backgroundColor = [UIColor clearColor];// 设为透明从而使得cell.backgroundColor有效.
  1129. // lineview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  1130. // [cell.contentView addSubview:lineview];// cell.contentView是个readonly属性,所以别想着替换contentView了.
  1131. return cell;
  1132. }
  1133. else if([type isEqualToString:@"container_ca"])
  1134. {
  1135. NSString *CellIdentifier = @"detail_item_container_ca";
  1136. DetailCellContainerCA *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1137. NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
  1138. cell.labelContainerNo.text = item[@"container#"];
  1139. cell.labelSealNo.text=item[@"seal_no"];
  1140. //cell.tapDelegate = self;
  1141. // UIView * lineview = [[LineView alloc] initWithFrame:cell.contentView.frame];
  1142. // lineview.userInteractionEnabled = NO;// 不设为NO会屏蔽cell的点击事件
  1143. // lineview.backgroundColor = [UIColor clearColor];// 设为透明从而使得cell.backgroundColor有效.
  1144. // lineview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  1145. // [cell.contentView addSubview:lineview];// cell.contentView是个readonly属性,所以别想着替换contentView了.
  1146. return cell;
  1147. }
  1148. else if([type isEqualToString:@"mapping"])
  1149. {
  1150. NSString *CellIdentifier = @"detail_item_kvnew";
  1151. DetailCellKVNew *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1152. NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
  1153. NSString* key =[item allKeys][0];
  1154. // [cell.keyLabel sizeToFit];
  1155. NSString* val=[item valueForKey:key];
  1156. // if([val isEqual:[NSNull null]])
  1157. // val=@"";
  1158. cell.keyLabel.text = key;
  1159. cell.valLabel.htmlText = val;
  1160. // if([key isEqualToString:@"Place_Of_Delivery"])
  1161. // {
  1162. //// int abc=0;
  1163. // }
  1164. NSLog(@"key %@ val %@",key,val);
  1165. cell.tapDelegate = self;
  1166. // UIView * lineview = [[LineView alloc] initWithFrame:cell.contentView.frame];
  1167. // lineview.userInteractionEnabled = NO;// 不设为NO会屏蔽cell的点击事件
  1168. // lineview.backgroundColor = [UIColor clearColor];// 设为透明从而使得cell.backgroundColor有效.
  1169. // lineview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  1170. // [cell.contentView addSubview:lineview];// cell.contentView是个readonly属性,所以别想着替换contentView了.
  1171. return cell;
  1172. // float width = tableView.frame.size.width;
  1173. //
  1174. // width-=CELL_MARGIN*2;
  1175. // CGSize constraintkey = CGSizeMake(width*0.4-2*LABEL_MARGIN, 20000.0f);//key label width is 40% cell width;
  1176. // CGSize constraintval = CGSizeMake(width*0.6-2*LABEL_MARGIN, 20000.0f);//val label width is 60% cell width;
  1177. // NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
  1178. // NSString* key =[item allKeys][0];
  1179. // // [cell.keyLabel sizeToFit];
  1180. // NSString* val=[item valueForKey:key];
  1181. // if([val isEqual:[NSNull null]])
  1182. // val=@"";
  1183. // if(val==nil)
  1184. // val=@"";
  1185. // if([val isEqualToString:@"null"])
  1186. // val=@"";
  1187. //
  1188. //
  1189. //
  1190. //
  1191. // CGRect frame;
  1192. // frame.size = constraintval;
  1193. // frame.origin.x=0;
  1194. // frame.origin.y=0;
  1195. // RTLabel* rtlabel = [[RTLabel alloc] initWithFrame:frame];
  1196. // [rtlabel setLineBreakMode: RTTextLineBreakModeWordWrapping];
  1197. // // rtlabel.lineSpacing = 20.0;
  1198. // [rtlabel setText: val];
  1199. // CGSize sizeval=rtlabel.optimumSize;
  1200. // CGSize sizekey = [key sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  1201. // // CGSize sizeval = [val sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintval lineBreakMode:NSLineBreakByWordWrapping];
  1202. //// DebugLog(@"tableView width:%f",width);
  1203. ////
  1204. //// DebugLog(@"key width= %f val width = %f",constraintkey.width,constraintval.width);
  1205. //// DebugLog(@"key = %@ val = %@",key,val);
  1206. // float height = MAX(sizekey.height,sizeval.height);
  1207. // height = MAX(height, DEF_CELL_HEIGHT-LINE_WIDTH);
  1208. // sizekey.height = height;
  1209. // sizekey.width = constraintkey.width;
  1210. // // sizeval.height = height;
  1211. // sizeval.width =constraintval.width;
  1212. //
  1213. // NSString *CellIdentifier = @"detail_item_kv";
  1214. // DetailCellKV *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1215. // if(cell==nil)
  1216. // DebugLog(@"cell is nil.........................");
  1217. //
  1218. //
  1219. // // CGRect framekey ;
  1220. // // framekey.origin.x=CELL_MARGIN;
  1221. // // framekey.origin.y=LINE_WIDTH;
  1222. // // framekey.size = sizekey;
  1223. // // UILabel* keyLabel = [[UILabel alloc]initWithFrame:framekey];
  1224. // // keyLabel.lineBreakMode = NSLineBreakByWordWrapping;
  1225. // // keyLabel.backgroundColor = [UIColor grayColor];
  1226. // // keyLabel.text = key;
  1227. // //
  1228. // // CGRect frameval;
  1229. // // frameval.origin.x=constraintkey.width+CELL_MARGIN;
  1230. // // frameval.origin.y=LINE_WIDTH;
  1231. // // frameval.size = sizeval;
  1232. // //
  1233. // // UILabel* valLabel = [[UILabel alloc]initWithFrame:frameval];
  1234. // // valLabel.lineBreakMode = NSLineBreakByWordWrapping;
  1235. // // valLabel.text = val;
  1236. // //
  1237. // // for(UIView* v in cell.contentView.subviews)
  1238. // // {
  1239. // // [v removeFromSuperview];
  1240. // //
  1241. // // }
  1242. // //
  1243. // // [cell.contentView addSubview:keyLabel];
  1244. // // [cell.contentView addSubview:valLabel];
  1245. //
  1246. //
  1247. // CGRect framekey = cell.keyLabel.frame;
  1248. // framekey.origin.x=CELL_MARGIN+LABEL_MARGIN;
  1249. // framekey.origin.y=LINE_WIDTH;
  1250. // framekey.size = sizekey;
  1251. // cell.keyLabel.frame = framekey;
  1252. // cell.keyLabel.text=key;
  1253. // CGRect frameval = cell.valLabel.frame;
  1254. // frameval.origin.x=constraintkey.width+CELL_MARGIN+3*LABEL_MARGIN; //2 margin for key 1 margin for value self
  1255. // frameval.origin.y=LINE_WIDTH;
  1256. // frameval.size = sizeval;
  1257. // cell.valLabel.frame = frameval;
  1258. // // [cell.valLabel setTextAlignment:RTTextAlignmentCenter];
  1259. // cell.valLabel.text= val;
  1260. // CGPoint rcenter;
  1261. // rcenter.x = width * 0.4+width * 0.6/2;
  1262. // rcenter.y = height /2;
  1263. // cell.valLabel.center=rcenter;
  1264. //// cell.valLabel.backgroundColor =[UIColor redColor];
  1265. //
  1266. //// cell.contentView.superview.backgroundColor = [UIColor clearColor];
  1267. //// cell.backgroundColor = [UIColor whiteColor];
  1268. // UIView * lineview = [[LineView alloc] initWithFrame:cell.contentView.frame];
  1269. // lineview.userInteractionEnabled = NO;// 不设为NO会屏蔽cell的点击事件
  1270. // lineview.backgroundColor = [UIColor clearColor];// 设为透明从而使得cell.backgroundColor有效.
  1271. // lineview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  1272. // [cell.contentView addSubview:lineview];// cell.contentView是个readonly属性,所以别想着替换contentView了.
  1273. //
  1274. //
  1275. //
  1276. // // [cell.valLabel sizeToFit];
  1277. // // cell.anameLabel.text = [field valueForKey:@"aname"];
  1278. // // [cell.anameLabel sizeToFit];
  1279. // // DebugLog(@"cellForRowAtIndexPath%@",[field valueForKey:@"aname"]);
  1280. // // Configure the cell...
  1281. // // CGRect rect = cell.frame;
  1282. // // [self.content set_itemheight:100 AtIndexPath:indexPath];
  1283. // return cell;
  1284. }
  1285. // else if ([type isEqualToString:@"communication"]) {
  1286. //
  1287. // NSInteger rowCount = [tableView numberOfRowsInSection:indexPath.section];
  1288. //
  1289. // NSMutableDictionary* segment = [self.content.segments[indexPath.section] mutableCopy];
  1290. //
  1291. // if (indexPath.row == 0) { // head
  1292. //
  1293. // AMCommHeadCell *cell = [tableView dequeueReusableCellWithIdentifier:COMM_ID_HEAD forIndexPath:indexPath];
  1294. //
  1295. // NSString *to = [segment objectForKey:@"receipt"];
  1296. // NSString *cc = [segment objectForKey:@"cc"];
  1297. //
  1298. // [cell setTo:to];
  1299. // [cell setCc:cc];
  1300. //
  1301. // cell.delegate = self;
  1302. //
  1303. // return cell;
  1304. //
  1305. // } else if (indexPath.row == rowCount - 1) { // edit
  1306. //
  1307. // AMCommEditCell *cell = [tableView dequeueReusableCellWithIdentifier:COMM_ID_EDIT forIndexPath:indexPath];
  1308. //
  1309. // NSString *editContent = [segment objectForKey:@"edit_content"];
  1310. // [cell setEmail:editContent];
  1311. // cell.delegate = self;
  1312. //
  1313. // return cell;
  1314. //
  1315. // } else { // content
  1316. //
  1317. // AMCommContentCell *cell = [tableView dequeueReusableCellWithIdentifier:COMM_ID_CONTENT forIndexPath:indexPath];
  1318. //
  1319. // NSDictionary *item = [segment objectForKey:[NSString stringWithFormat:@"item%ld",indexPath.row - 1]];
  1320. //
  1321. // NSString *sender = [item objectForKey:@"Sender"];
  1322. // NSString *content = [item objectForKey:@"msg"];
  1323. // NSString *time = [item objectForKey:@"mst_time"];
  1324. // NSString *email = [item objectForKey:@"email_url"];
  1325. //
  1326. //
  1327. // [cell setSender:sender];
  1328. // [cell setContent:content];
  1329. // [cell setTime:time];
  1330. // [cell setEmail:email];
  1331. //
  1332. // cell.delegate = self;
  1333. //
  1334. // return cell;
  1335. //
  1336. // }
  1337. // }
  1338. else if([type isEqualToString:@"log"])
  1339. {
  1340. DebugLog(@"cellForRowAtIndexPath =====> list");
  1341. static NSString *CellIdentifier = @"detail_item_list";
  1342. // float width = tableView.frame.size.width;
  1343. //
  1344. // width-=CELL_MARGIN*2;
  1345. // CGSize constraintkey = CGSizeMake(width, 20000.0f);//key label width is 40% cell width;
  1346. // NSDictionary* item = self.content.segments[indexPath.section];
  1347. NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
  1348. NSString* val=item[@"text"];
  1349. bool bg =[item[@"bg"] boolValue];
  1350. if([val isEqual:[NSNull null]])
  1351. val=@"";
  1352. if(val==nil)
  1353. val=@"";
  1354. if([val isEqualToString:@"null"])
  1355. val=@"";
  1356. // CGSize sizeval = [val sizeWithFont:[UIFont systemFontOfSize:13.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  1357. // CGSize sizeval = [val boundingRectWithSize:constraintkey options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading) attributes: @{NSFontAttributeName: [UIFont systemFontOfSize:13.0]} context:nil].size;
  1358. //
  1359. // float height = sizeval.height;
  1360. // height = MAX(height, DEF_CELL_HEIGHT-LINE_WIDTH);
  1361. // sizeval.height = height;
  1362. // sizeval.width = constraintkey.width;
  1363. //创建cell
  1364. DetailCellList *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1365. // CGRect framekey = cell.listLabel.frame;
  1366. // framekey.origin.x=CELL_MARGIN;
  1367. // framekey.origin.y=LINE_WIDTH;
  1368. // framekey.size = sizeval;
  1369. // cell.listLabel.frame = framekey;
  1370. cell.listLabel.text= val;
  1371. if(bg)
  1372. cell.contentView.backgroundColor = LogBGColor1;
  1373. else
  1374. cell.contentView.backgroundColor = LogBGColor0;
  1375. return cell;
  1376. }
  1377. else
  1378. {
  1379. DebugLog(@"cellForRowAtIndexPath =====> list");
  1380. static NSString *CellIdentifier = @"detail_item_list";
  1381. // float width = tableView.frame.size.width;
  1382. //
  1383. // width-=CELL_MARGIN*2;
  1384. // CGSize constraintkey = CGSizeMake(width, 20000.0f);//key label width is 40% cell width;
  1385. //
  1386. NSDictionary* item = self.content.segments[indexPath.section];
  1387. NSString* val=[item valueForKey:[NSString stringWithFormat:@"line%ld",(long)indexPath.row]];
  1388. if([val isEqual:[NSNull null]])
  1389. val=@"";
  1390. if(val==nil)
  1391. val=@"";
  1392. if([val isEqualToString:@"null"])
  1393. val=@"";
  1394. // CGSize sizeval = [val sizeWithFont:[UIFont systemFontOfSize:13.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  1395. // CGSize sizeval = [val boundingRectWithSize:constraintkey options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading) attributes: @{NSFontAttributeName: [UIFont systemFontOfSize:13.0]} context:nil].size;
  1396. //
  1397. // float height = sizeval.height;
  1398. // height = MAX(height, DEF_CELL_HEIGHT-LINE_WIDTH);
  1399. // sizeval.height = height;
  1400. // sizeval.width = constraintkey.width;
  1401. //创建cell
  1402. DetailCellList *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1403. // CGRect framekey = cell.listLabel.frame;
  1404. // framekey.origin.x=CELL_MARGIN;
  1405. // framekey.origin.y=LINE_WIDTH;
  1406. // framekey.size = sizeval;
  1407. // cell.listLabel.frame = framekey;
  1408. cell.listLabel.text= val;
  1409. return cell;
  1410. }
  1411. return nil;
  1412. }
  1413. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  1414. NSMutableDictionary* segment = [self.content.segments[indexPath.section] mutableCopy];
  1415. NSString* type =[segment valueForKey:@"_type"];
  1416. NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
  1417. if(([type isEqualToString: @"container"]||[type isEqualToString: @"container_ca"])&& [item[@"commodity"] boolValue])
  1418. {
  1419. NSString* cid=[item[@"id"] stringValue];
  1420. NSMutableDictionary* param =[NSMutableDictionary new];
  1421. param[@"action"]=@"detail";
  1422. param[@"sub_type"]=@"container";
  1423. param[@"action_type"]=@"Container Detail";
  1424. param[@"id"]= cid;
  1425. UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Detail" bundle:[NSBundle mainBundle]];
  1426. DetailPageViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"DetailPageViewController"];
  1427. vc.function_name = @"Container Detail";
  1428. vc.params = param;
  1429. [vc setTitle:@"Container Detail"];
  1430. // ResultViewController *vc = [ResultViewController resultViewController:params];
  1431. [self.navigationController pushViewController:vc animated:YES];
  1432. }
  1433. // NSString* port = self.content.originContent[@"backup_port"];
  1434. // if([type isEqualToString:@"tracking"]) {
  1435. // NSDictionary *location = [segment objectForKey:@"location"];
  1436. // [self.shipMap showShipAnnotaion:location backupLocation:port];
  1437. // self.containerSelectedIndexPath = indexPath;
  1438. // }
  1439. }
  1440. #pragma mark - Quick Look
  1441. - (MyQLPreviewController *)quickLook {
  1442. if (!_quickLook)
  1443. {
  1444. _quickLook = [[MyQLPreviewController alloc] init];
  1445. _quickLook.delegate = self;
  1446. _quickLook.dataSource = self;
  1447. }
  1448. else
  1449. {
  1450. [_quickLook reloadData];
  1451. }
  1452. return _quickLook;
  1453. }
  1454. #pragma mark - QuickLook Data Source
  1455. - (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller {
  1456. return 1;
  1457. }
  1458. - (id <QLPreviewItem>) previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index {
  1459. return [NSURL fileURLWithPath:self.documentPath];
  1460. }
  1461. #pragma mark - QuickLook Delegate
  1462. - (void) previewControllerDidDismiss:(QLPreviewController *)controller {
  1463. }
  1464. /**
  1465. * 文件内部链接点击不进行外部跳转
  1466. */
  1467. - (BOOL) previewController:(QLPreviewController *)controller shouldOpenURL:(NSURL *)url forPreviewItem:(id<QLPreviewItem>)item {
  1468. return NO;
  1469. }
  1470. #pragma mark - KVDetail Tap Delegate
  1471. - (void)detailCell:(DetailCellKVNew *)cell doubleTapedForValue:(NSString *)value {
  1472. // NSIndexPath *indexPath = [self.table indexPathForCell:cell];
  1473. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  1474. pasteboard.string = value;
  1475. [DetailHUD show:[NSString stringWithFormat:@"%@ Copied",cell.keyLabel.text] inView:self.view];
  1476. }
  1477. #pragma mark - Quick Look Menu Action
  1478. - (void)saveDocument {
  1479. NSMutableDictionary *emailInfo = [NSMutableDictionary new];
  1480. if (self.email.length==0) {
  1481. self.email=@"";
  1482. }
  1483. if (self.email_subject.length==0) {
  1484. self.email_subject=@"";
  1485. }
  1486. if (self.email_content.length==0) {
  1487. self.email_content=@"";
  1488. }
  1489. [emailInfo setValue:self.email forKey:@"reciptions"];
  1490. [emailInfo setValue:self.email_subject forKey:@"subject"];
  1491. [emailInfo setValue:self.email_content forKey:@"content"];
  1492. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  1493. NSString *path = [paths objectAtIndex:0];
  1494. NSString *filePath = [path stringByAppendingPathComponent:[self.documentPath lastPathComponent]];
  1495. NSString *emailPath = [path stringByAppendingPathComponent:[NSString stringWithFormat:@".%@",[[self.documentPath stringByDeletingPathExtension] lastPathComponent]]];
  1496. NSError *err;
  1497. if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
  1498. [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
  1499. }
  1500. [[NSFileManager defaultManager] moveItemAtPath:self.documentPath toPath:filePath error:&err];
  1501. NSData* saved_email_data = [RAConvertor dict2data:emailInfo];
  1502. [saved_email_data writeToFile:emailPath atomically:NO];
  1503. UIAlertController *alertVC;
  1504. UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1505. }];
  1506. if (err) {
  1507. alertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"save document failed:\n%@",err.localizedDescription] preferredStyle:UIAlertControllerStyleAlert];
  1508. } else {
  1509. alertVC = [UIAlertController alertControllerWithTitle:nil message:@"Document Saved" preferredStyle:UIAlertControllerStyleAlert];
  1510. }
  1511. [alertVC addAction:action];
  1512. [self presentViewController:alertVC animated:YES completion:nil];
  1513. }
  1514. - (void)shareDocument {
  1515. return [self share_activity];
  1516. }
  1517. -(void) share_activity
  1518. {
  1519. // 设置分享内容
  1520. // NSString *text = @"分享内容";
  1521. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  1522. NSString *path = [paths objectAtIndex:0];
  1523. NSString *filePath = [path stringByAppendingPathComponent:[self.documentPath lastPathComponent]];
  1524. // 没有保存的情况
  1525. if ([[NSFileManager defaultManager] fileExistsAtPath:self.documentPath]) {
  1526. filePath = self.documentPath;
  1527. }
  1528. NSURL *url = [NSURL fileURLWithPath:filePath];
  1529. NSArray *activityItems = @[url];
  1530. LPShareActivity *share = [[LPShareActivity alloc] init];
  1531. share.to = [self.email componentsSeparatedByString:@","];//@[@"676767@qq.com"];
  1532. share.subject = self.email_subject;//@"test subject";
  1533. share.body = self.email_content;// @"body";
  1534. share.filePath = filePath;
  1535. share.handle = ^(UIViewController *vc) {
  1536. [self presentViewController:vc animated:YES completion:^{
  1537. // [share activityDidFinish:YES];
  1538. // ...
  1539. }];
  1540. };
  1541. // 服务类型控制器
  1542. UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:@[share]];
  1543. // _activityViewController = activityViewController;
  1544. // activityViewController.excludedActivityTypes = @[UIActivityTypeMail];
  1545. activityViewController.modalInPopover = true;
  1546. [self presentViewController:activityViewController animated:YES completion:nil];
  1547. // 选中分享类型
  1548. [activityViewController setCompletionWithItemsHandler:^(NSString * __nullable activityType, BOOL completed, NSArray * __nullable returnedItems, NSError * __nullable activityError){
  1549. // 显示选中的分享类型
  1550. NSLog(@"act type %@",activityType);
  1551. if (completed) {
  1552. NSLog(@"ok");
  1553. }else {
  1554. NSLog(@"not ok");
  1555. }
  1556. }];
  1557. }
  1558. - (void)quickLookMenuClick:(id)sender {
  1559. UIAlertController *menuAlert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  1560. __weak typeof(self) weakSelf = self;
  1561. UIAlertAction *saveAction = [UIAlertAction actionWithTitle:@"Save Document" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1562. [weakSelf saveDocument];
  1563. }];
  1564. UIAlertAction *shareAction = [UIAlertAction actionWithTitle:@"Share Document" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1565. [weakSelf shareDocument];
  1566. }];
  1567. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  1568. }];
  1569. // [menuAlert addAction:saveAction];
  1570. [menuAlert addAction:shareAction];
  1571. [menuAlert addAction:cancelAction];
  1572. [self presentViewController:menuAlert animated:YES completion:nil];
  1573. }
  1574. //
  1575. //#pragma mark - Keyboard
  1576. //
  1577. //- (void)startListenKeyboard {
  1578. // NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
  1579. // // 键盘通知
  1580. // [notificationCenter addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
  1581. // [notificationCenter addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
  1582. // [notificationCenter addObserver:self selector:@selector(keyboardChangeFrame:) name:UIKeyboardDidChangeFrameNotification object:nil];
  1583. //
  1584. // UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapToHideKeyboard:)];
  1585. // [self.view addGestureRecognizer:tap];
  1586. // self.tap = tap;
  1587. //}
  1588. //
  1589. //- (void)stopListenKeyboard {
  1590. // NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
  1591. // [notificationCenter removeObserver:self];
  1592. //
  1593. // [self.view removeGestureRecognizer:self.tap];
  1594. //}
  1595. //
  1596. //- (void)tapToHideKeyboard:(UITapGestureRecognizer *)tap {
  1597. // [self.view endEditing:YES];
  1598. //}
  1599. //
  1600. ///**键盘隐藏*/
  1601. //- (void)keyboardWillHide:(NSNotification *)notification {
  1602. // NSLog(@"keyboard hide");
  1603. // self.showKeyboard = NO;
  1604. //}
  1605. //
  1606. ///**键盘显示*/
  1607. //- (void)keyboardWillShow:(NSNotification *)notification {
  1608. //
  1609. //// NSTimeInterval duration = [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
  1610. //// CGRect begin = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];
  1611. //// CGRect end = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
  1612. ////
  1613. //// if (duration == 0) {
  1614. //// duration = 0.25;
  1615. //// }
  1616. // NSLog(@"keyboard show");
  1617. // self.showKeyboard = YES;
  1618. //}
  1619. //
  1620. ///**在使用过程中切换键盘*/
  1621. //- (void)keyboardChangeFrame:(NSNotification *)notification {
  1622. //
  1623. // NSLog(@"keyboard change frame");
  1624. //
  1625. // NSTimeInterval duration = [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
  1626. //// CGRect begin = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];
  1627. // CGRect end = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
  1628. //
  1629. // if (duration == 0) {
  1630. // duration = 0.25;
  1631. // }
  1632. //
  1633. // NSLayoutConstraint *bottom_constraint = nil;
  1634. // for (NSLayoutConstraint *constraint in self.view.constraints) {
  1635. // if ([constraint.identifier isEqualToString:@"table_bottom_constraint"]) {
  1636. // bottom_constraint = constraint;
  1637. // break;
  1638. // }
  1639. // }
  1640. //
  1641. // CGFloat tabBarY = CGRectGetMinY(self.tabBarController.tabBar.frame);
  1642. //
  1643. // CGFloat offset = tabBarY - CGRectGetMinY(end);
  1644. // if (offset < 0) {
  1645. // offset = 0;
  1646. // }
  1647. //
  1648. // if (bottom_constraint) {
  1649. // bottom_constraint.constant = offset;
  1650. // [self.view layoutIfNeeded];
  1651. //
  1652. // if (self.editingIndexPath) {
  1653. // [self.table scrollToRowAtIndexPath:self.editingIndexPath atScrollPosition:UITableViewScrollPositionNone animated:UITableViewRowAnimationNone];
  1654. // }
  1655. // }
  1656. //
  1657. // CGSize contentSize = self.table.contentSize;
  1658. // CGPoint contentOffset = self.table.contentOffset;
  1659. // offset = contentOffset.y - (contentSize.height - CGRectGetHeight(self.table.bounds));
  1660. // if (offset > 0) {
  1661. // contentOffset.y -= offset;
  1662. // self.table.contentOffset = contentOffset;
  1663. // }
  1664. //
  1665. //}
  1666. //#pragma mark - COMM Head Delegate
  1667. //
  1668. //- (void)commHeadCell:(AMCommHeadCell *)cell didChangeCC:(NSString *)cc {
  1669. //
  1670. // NSIndexPath *indexPath = [self.table indexPathForCell:cell];
  1671. //
  1672. // [self cc:cc changedForIndexPath:indexPath];
  1673. //}
  1674. //
  1675. //- (void)commHeadCell:(AMCommHeadCell *)cell didBeginEditing:(UITextField *)textField {
  1676. // self.editingCell = cell;
  1677. // self.editingIndexPath = [self.table indexPathForCell:cell];
  1678. //}
  1679. //
  1680. //- (void)commHeadCell:(AMCommHeadCell *)cell didEndEditing:(UITextField *)textField {
  1681. // self.editingCell = nil;
  1682. // self.editingIndexPath = nil;
  1683. //}
  1684. //
  1685. //- (void)commHeadCell:(AMCommHeadCell *)cell didClickContactButton:(UIButton *)button {
  1686. //
  1687. // self.contactSelectIndexPath = [self.table indexPathForCell:cell];
  1688. //
  1689. // CNContactPickerViewController *contactVC = [[CNContactPickerViewController alloc] init];
  1690. // contactVC.delegate = self;
  1691. //
  1692. //
  1693. // [self presentViewController:contactVC animated:YES completion:nil];
  1694. //}
  1695. //
  1696. //#pragma mark - COMM Content Delegate
  1697. //
  1698. //- (void)commContentCell:(AMCommContentCell *)cell sendEmail:(NSString *)email {
  1699. //
  1700. //// MFMailComposeViewController *emailVC = [[MFMailComposeViewController alloc] init];
  1701. //// if (!emailVC) {
  1702. ////
  1703. //// return;
  1704. //// }
  1705. //// [emailVC setMessageBody:[NSString stringWithFormat:@"<a>%@</a>",email] isHTML:YES];
  1706. ////
  1707. //// [self presentViewController:emailVC animated:YES completion:nil];
  1708. //
  1709. // NSURL *url = [NSURL URLWithString:email];
  1710. // if ([[UIApplication sharedApplication] canOpenURL:url]) {
  1711. // [[UIApplication sharedApplication] openURL:url];
  1712. // }
  1713. //
  1714. //}
  1715. //
  1716. //#pragma mark - COMM Edit Delegate
  1717. //
  1718. //- (void)commEditCell:(AMCommEditCell *)cell clickToSendEmail:(NSString *)email {
  1719. //
  1720. // // 检查Email内容是否为空
  1721. // if (!email || email.length == 0) {
  1722. //
  1723. // UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Warning" message:@"The communication message that will be sent is blank" preferredStyle:UIAlertControllerStyleAlert];
  1724. // UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1725. //
  1726. // }];
  1727. // [alert addAction:okAction];
  1728. // [self presentViewController:alert animated:YES completion:nil];
  1729. // return;
  1730. // }
  1731. //
  1732. // NSIndexPath *indexPath = [self.table indexPathForCell:cell];
  1733. // NSMutableDictionary* segment = [self.content.segments[indexPath.section] mutableCopy];
  1734. // NSString *cc = [segment objectForKey:@"cc"];
  1735. // if (cc && cc.length > 0) {
  1736. //
  1737. // // 校验邮箱地址格式是否有效
  1738. // NSArray *ccArr = [cc componentsSeparatedByString:@";"];
  1739. // for (NSString *ccStr in ccArr) {
  1740. // if (ccStr.length > 0) {
  1741. // BOOL isEmail = [self validateEmail:ccStr];
  1742. // if (!isEmail) {
  1743. // UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Warning" message:@"The communication cc is not right" preferredStyle:UIAlertControllerStyleAlert];
  1744. // UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1745. //
  1746. // }];
  1747. // [alert addAction:okAction];
  1748. // [self presentViewController:alert animated:YES completion:nil];
  1749. // return;
  1750. // }
  1751. // }
  1752. // }
  1753. //
  1754. // // 校验通过
  1755. //
  1756. // }
  1757. //
  1758. // UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:@"send email" preferredStyle:UIAlertControllerStyleAlert];
  1759. // [self presentViewController:alert animated:YES completion:nil];
  1760. //
  1761. // NSString *serialNo = [segment objectForKey:@"serial_no"];
  1762. //
  1763. // __weak typeof(self) weakSelf = self;
  1764. //
  1765. // [RANetwork request_sendemail:email CC:cc SerialNo:serialNo completionHandler:^(NSMutableDictionary *result) {
  1766. // NSDictionary *sendResponse=result;
  1767. // [alert dismissViewControllerAnimated:YES completion:^{
  1768. //
  1769. // if (weakSelf) {
  1770. // __strong typeof(weakSelf) strongSelf = weakSelf;
  1771. // int result = [[sendResponse objectForKey:@"result"] intValue];
  1772. //
  1773. // if (result == RESULT_TRUE) {
  1774. //
  1775. // } else {
  1776. // NSString *msg = [sendResponse objectForKey:@"err_msg"];
  1777. // if (msg == nil) {
  1778. // msg = @"Sorry,something wrong";
  1779. // }
  1780. // UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:msg preferredStyle:UIAlertControllerStyleAlert];
  1781. // UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1782. //
  1783. // }];
  1784. // [alert addAction:okAction];
  1785. // [strongSelf presentViewController:alert animated:YES completion:nil];
  1786. // }
  1787. //
  1788. // }
  1789. //
  1790. // }];
  1791. // }];
  1792. //
  1793. // return;
  1794. //
  1795. // dispatch_async(dispatch_get_global_queue(0, 0), ^{
  1796. // NSDictionary *sendResponse = [RANetwork sendEmail:email CC:cc SerialNo:serialNo];
  1797. // dispatch_async(dispatch_get_main_queue(), ^{
  1798. //
  1799. // [alert dismissViewControllerAnimated:YES completion:^{
  1800. //
  1801. // if (weakSelf) {
  1802. // __strong typeof(weakSelf) strongSelf = weakSelf;
  1803. // int result = [[sendResponse objectForKey:@"result"] intValue];
  1804. //
  1805. // if (result == RESULT_TRUE) {
  1806. //
  1807. // } else {
  1808. // NSString *msg = [sendResponse objectForKey:@"err_msg"];
  1809. // if (msg == nil) {
  1810. // msg = @"Sorry,something wrong";
  1811. // }
  1812. // UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:msg preferredStyle:UIAlertControllerStyleAlert];
  1813. // UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1814. //
  1815. // }];
  1816. // [alert addAction:okAction];
  1817. // [strongSelf presentViewController:alert animated:YES completion:nil];
  1818. // }
  1819. //
  1820. // }
  1821. //
  1822. // }];
  1823. //
  1824. // });
  1825. // });
  1826. //
  1827. //
  1828. //}
  1829. //
  1830. //- (void)commEditCell:(AMCommEditCell *)cell didChangeEmail:(NSString *)email {
  1831. // // 保存数据
  1832. // NSIndexPath *indexPath = [self.table indexPathForCell:cell];
  1833. //
  1834. // NSMutableDictionary* segment = [self.content.segments[indexPath.section] mutableCopy];
  1835. // if (email && email.length > 0) {
  1836. // [segment setValue:email forKey:@"edit_content"];
  1837. // } else {
  1838. // [segment removeObjectForKey:@"edit_content"];
  1839. // }
  1840. //
  1841. // NSMutableArray *arr = [self.content.segments mutableCopy];
  1842. // [arr replaceObjectAtIndex:indexPath.section withObject:segment];
  1843. // self.content.segments = arr;
  1844. //
  1845. // // 调用 tableView 的 beginUpdates 和 endUpdates,重新计算 cell 的高度
  1846. // [self.table beginUpdates];
  1847. // [self.table endUpdates];
  1848. //
  1849. // // 防止在输入的时候超出屏幕区域
  1850. // CGRect frame = cell.frame;
  1851. // if (CGRectGetMaxY(frame) > CGRectGetMaxY(self.table.bounds)) {
  1852. // [self.table scrollRectToVisible:frame animated:NO];
  1853. // }
  1854. //}
  1855. //
  1856. //- (void)commEditCell:(AMCommEditCell *)cell didBeginEditing:(UITextView *)textView {
  1857. // self.editingCell = cell;
  1858. // self.editingIndexPath = [self.table indexPathForCell:cell];
  1859. //}
  1860. //
  1861. //- (void)commEditCell:(AMCommEditCell *)cell didEndEditing:(UITextView *)textView {
  1862. // self.editingCell = nil;
  1863. // self.editingIndexPath = nil;
  1864. //}
  1865. //
  1866. //#pragma mark - Contact Picker Delegate
  1867. //
  1868. //- (void)contactPickerDidCancel:(CNContactPickerViewController *)picker {
  1869. //
  1870. // self.contactSelectIndexPath = nil;
  1871. //}
  1872. //
  1873. //- (void)contactPicker:(CNContactPickerViewController *)picker didSelectContact:(CNContact *)contact {
  1874. //
  1875. // [self handleSelectContact:contact];
  1876. //
  1877. // self.contactSelectIndexPath = nil;
  1878. //}
  1879. //
  1880. //- (void)contactPicker:(CNContactPickerViewController *)picker didSelectContacts:(NSArray<CNContact *> *)contacts {
  1881. //
  1882. // for (CNContact *contact in contacts) {
  1883. // [self handleSelectContact:contact];
  1884. // }
  1885. //
  1886. // self.contactSelectIndexPath = nil;
  1887. //}
  1888. //
  1889. //- (void)contactPicker:(CNContactPickerViewController *)picker didSelectContactProperty:(CNContactProperty *)contactProperty {
  1890. //
  1891. // self.contactSelectIndexPath = nil;
  1892. //}
  1893. //
  1894. //- (void)contactPicker:(CNContactPickerViewController *)picker didSelectContactProperties:(NSArray<CNContactProperty *> *)contactProperties {
  1895. //
  1896. // self.contactSelectIndexPath = nil;
  1897. //}
  1898. //
  1899. //#pragma mark - Utils
  1900. //
  1901. //- (BOOL)validateEmail:(NSString *)email {
  1902. //
  1903. // NSString *emailRegex =@"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
  1904. //
  1905. // NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
  1906. //
  1907. // return [emailTest evaluateWithObject:email];
  1908. //}
  1909. //
  1910. //- (void)handleSelectContact:(CNContact *)contact {
  1911. //
  1912. // NSArray *emailArr = [contact emailAddresses];
  1913. // for (CNLabeledValue *value in emailArr) {
  1914. // if ([value.label isEqualToString:CNLabelWork]) {
  1915. // [self appendCC:[NSString stringWithFormat:@"%@;",value.value] forIndexPath:self.contactSelectIndexPath];
  1916. // [self.table reloadRowsAtIndexPaths:@[self.contactSelectIndexPath] withRowAnimation:UITableViewRowAnimationNone];
  1917. // AMCommHeadCell *cell = [self.table cellForRowAtIndexPath:self.contactSelectIndexPath];
  1918. // [cell beginEditing];
  1919. // break;
  1920. // }
  1921. // }
  1922. //
  1923. //}
  1924. //
  1925. //- (void)appendCC:(NSString *)cc forIndexPath:(NSIndexPath *)indexPath {
  1926. // if (indexPath == nil || cc == nil || cc.length == 0) {
  1927. // return;
  1928. // }
  1929. // NSMutableDictionary* segment = [self.content.segments[indexPath.section] mutableCopy];
  1930. // NSString *oldCC = [segment objectForKey:@"cc"];
  1931. // if (oldCC == nil || oldCC.length == 0) {
  1932. // oldCC = cc;
  1933. // } else {
  1934. // if ([[oldCC substringFromIndex:oldCC.length - 1] isEqualToString:@";"]) {
  1935. // oldCC = [oldCC stringByAppendingString:cc];
  1936. // } else {
  1937. // oldCC = [oldCC stringByAppendingString:[NSString stringWithFormat:@";%@",cc]];
  1938. // }
  1939. // }
  1940. //
  1941. // [self cc:oldCC changedForIndexPath:indexPath];
  1942. //}
  1943. //
  1944. //- (void)cc:(NSString *)cc changedForIndexPath:(NSIndexPath *)indexPath {
  1945. // if (indexPath == nil) {
  1946. // return;
  1947. // }
  1948. // NSMutableDictionary* segment = [self.content.segments[indexPath.section] mutableCopy];
  1949. // if (cc && cc.length > 0) {
  1950. // [segment setValue:cc forKey:@"cc"];
  1951. // } else {
  1952. // [segment removeObjectForKey:@"cc"];
  1953. // }
  1954. //
  1955. // NSMutableArray *arr = [self.content.segments mutableCopy];
  1956. // [arr replaceObjectAtIndex:indexPath.section withObject:segment];
  1957. // self.content.segments = arr;
  1958. //}
  1959. //
  1960. //#pragma mark - ShipMap Delegate
  1961. //
  1962. //- (void)shipMap:(AMShipMap *)shipMap tryToZoomIn:(BOOL)zoomIn {
  1963. //
  1964. // if (zoomIn) {
  1965. //
  1966. // NSArray *constraints = self.view.constraints;
  1967. // NSLayoutConstraint *h_ratio_constraint = nil;
  1968. //
  1969. // for (NSLayoutConstraint *constraint in constraints) {
  1970. // if (constraint.identifier && [constraint.identifier isEqualToString:@"ratio_constraint"]) {
  1971. // h_ratio_constraint = constraint;
  1972. // }
  1973. // }
  1974. //
  1975. // if (h_ratio_constraint) {
  1976. // [self.view removeConstraint:h_ratio_constraint];
  1977. // }
  1978. //
  1979. // NSLayoutConstraint *table_h_constraint = [NSLayoutConstraint constraintWithItem:self.table
  1980. // attribute:NSLayoutAttributeHeight
  1981. // relatedBy:NSLayoutRelationEqual
  1982. // toItem:nil
  1983. // attribute:NSLayoutAttributeNotAnAttribute
  1984. // multiplier:0
  1985. // constant:0];
  1986. // table_h_constraint.identifier = @"table_height";
  1987. // [self.view addConstraint:table_h_constraint];
  1988. //
  1989. // } else {
  1990. //
  1991. // NSArray *constraints = self.view.constraints;
  1992. // NSLayoutConstraint *h_constraint = nil;
  1993. //
  1994. // for (NSLayoutConstraint *constraint in constraints) {
  1995. // if (constraint.identifier && [constraint.identifier isEqualToString:@"table_height"]) {
  1996. // h_constraint = constraint;
  1997. // }
  1998. // }
  1999. //
  2000. // if (h_constraint) {
  2001. // [self.view removeConstraint:h_constraint];
  2002. // }
  2003. //
  2004. // float h_ratio = 0.5;
  2005. // NSLayoutConstraint *h_ratio_constraint = [NSLayoutConstraint constraintWithItem:shipMap
  2006. // attribute:NSLayoutAttributeHeight
  2007. // relatedBy:NSLayoutRelationEqual
  2008. // toItem:self.table
  2009. // attribute:NSLayoutAttributeHeight
  2010. // multiplier:h_ratio
  2011. // constant:0];
  2012. // h_ratio_constraint.identifier = @"ratio_constraint";
  2013. //
  2014. // [self.view addConstraint:h_ratio_constraint];
  2015. // }
  2016. //
  2017. //
  2018. // [self.view layoutIfNeeded];
  2019. //}
  2020. @end