ResultViewController.m 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275
  1. //
  2. // ViewController.m
  3. // phoneTest
  4. //
  5. // Created by Ray on 01/09/2017.
  6. //
  7. //
  8. #define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
  9. #import "ResultViewController.h"
  10. #import "FullyShowViewController.h"
  11. #import "RANetwork.h"
  12. #import "RAUtils.h"
  13. #import "JLRefreshHeader.h"
  14. #import "JLRefreshFooter.h"
  15. //#import "OrderDetailViewController.h"
  16. //#import "KVViewController.h"
  17. #import <QuickLook/QuickLook.h>
  18. #import "config.h"
  19. #import "RAConvertor.h"
  20. #import "RAUtils.h"
  21. //#import "RTLabel.h"
  22. #import "ResultCell.h"
  23. #import <AudioToolbox/AudioToolbox.h>
  24. const int delta = 25;
  25. @interface ResultViewController () <JLRefreshDelegate,QLPreviewControllerDataSource,QLPreviewControllerDelegate,UIViewControllerPreviewingDelegate,ResultCellTouchDelegate,UITableViewDelegate,UITableViewDataSource>
  26. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *w_constraint;
  27. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *h_constraint;
  28. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *trail_constraint;
  29. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *lead_constraint;
  30. @end
  31. @implementation ResultViewController
  32. + (instancetype)buildInstanceWithParams:(NSMutableDictionary *)params {
  33. id resultVC = [[self alloc] initWithNibName:@"Result" bundle:nil];
  34. ((ResultViewController *)resultVC).params = params;
  35. return resultVC;
  36. }
  37. - (void)labelClick {
  38. NSLog(@"underlineLabel被点击了");
  39. }
  40. - (void)resetContraint {
  41. for (NSLayoutConstraint *constraint in self.view.constraints) {
  42. if ([constraint.identifier isEqualToString:@"title_top"] ) {
  43. [self.view removeConstraint:constraint];
  44. }
  45. if ([constraint.identifier isEqualToString:@"scroll_bottom"]) {
  46. [self.view removeConstraint:constraint];
  47. }
  48. }
  49. NSLayoutConstraint *scroll_top = [NSLayoutConstraint constraintWithItem:self.titleBar
  50. attribute:NSLayoutAttributeTop
  51. relatedBy:NSLayoutRelationEqual
  52. toItem:self.topLayoutGuide
  53. attribute:NSLayoutAttributeBottom
  54. multiplier:1.0
  55. constant:0];
  56. NSLayoutConstraint *scroll_bottom = [NSLayoutConstraint constraintWithItem:self.scrollview
  57. attribute:NSLayoutAttributeBottom
  58. relatedBy:NSLayoutRelationEqual
  59. toItem:self.bottomLayoutGuide
  60. attribute:NSLayoutAttributeTop
  61. multiplier:1.0
  62. constant:0];
  63. [self.view addConstraint:scroll_top];
  64. [self.view addConstraint:scroll_bottom];
  65. CGFloat height = self.bottomLayoutGuide.length;
  66. self.bottom_mask_constraint.constant = height;
  67. }
  68. - (void)viewDidLayoutSubviews {
  69. [super viewDidLayoutSubviews];
  70. [self resetContraint];
  71. }
  72. - (void)viewDidLoad {
  73. [super viewDidLoad];
  74. self.default_row_text_size=14;
  75. self.default_title_text_size=17;
  76. self.default_line_color = 0x000000;
  77. self.titleLabel.text = nil;
  78. // self.labelTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelTapAction:)];
  79. //
  80. // self.labelTap.numberOfTouchesRequired = 1; //手指数
  81. // self.labelTap.numberOfTapsRequired = 2; //tap次数
  82. //
  83. //
  84. //
  85. //
  86. // self.cellDoubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cellDoubleTapAction:)];
  87. //
  88. // self.cellDoubleTap.numberOfTouchesRequired = 1; //手指数
  89. // self.cellDoubleTap.numberOfTapsRequired = 2; //tap次数
  90. // UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self
  91. // action:nil];
  92. // singleFingerOne.numberOfTouchesRequired = 1; //手指数
  93. // singleFingerOne.numberOfTapsRequired = 1; //tap次数
  94. //
  95. //
  96. // singleFingerTwo.delegate = self;
  97. self.label = [MDHTMLLabel new];
  98. self.label.font = [UIFont systemFontOfSize:self.default_row_text_size];
  99. self.label.textInsets = UIEdgeInsetsMake(0.f, 8.f, 0.f, 8.f);
  100. // NSString* Path = [[NSBundle mainBundle] pathForResource:@"layout.json" ofType:nil];
  101. //
  102. // NSData *data = [NSData dataWithContentsOfFile:Path];
  103. // self.content_layout = [[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil] mutableCopy];
  104. //
  105. //
  106. // Path = [[NSBundle mainBundle] pathForResource:@"data.json" ofType:nil];
  107. //
  108. // data = [NSData dataWithContentsOfFile:Path];
  109. // self.content_data = [[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil] mutableCopy];
  110. // int width=[self.content_layout[@"header"][@"width"] intValue];
  111. // if(width<self.tableview.frame.size.width)
  112. // width=self.tableview.frame.size.width;
  113. //
  114. // CGRect frame = CGRectMake(self.tableview.frame.origin.x, self.tableview.frame.origin.y, width, self.tableview.frame.size.height);
  115. // self.tableview.frame=frame;
  116. // self.scrollview.contentSize=self.tableview.frame.size;
  117. // Do any additional setup after loading the view, typically from a nib.
  118. self.automaticallyAdjustsScrollViewInsets = NO;
  119. self.tableview.tableFooterView = [UIView new];
  120. [self setupNavigationBar];
  121. [self configureTableView];
  122. [self setupTableRefreshView];
  123. [self loadContent];
  124. // self.tableview.tableHeaderView = [self get_tableHeader];
  125. }
  126. - (void)viewWillAppear:(BOOL)animated {
  127. [super viewWillAppear:animated];
  128. }
  129. -(void)labelTapAction:(UIGestureRecognizer*)gestureRecognizer
  130. {
  131. NSLog(@"label touched");
  132. MDHTMLLabel* label = (MDHTMLLabel*)[gestureRecognizer view];
  133. NSIndexPath* index =[self.tableview indexPathForCell:(UITableViewCell*)label.superview];
  134. self.tableview.allowsSelection = true;
  135. [self.tableview selectRowAtIndexPath:index animated:NO scrollPosition:UITableViewScrollPositionNone];
  136. self.label.htmlText = label.htmlText;
  137. [self.label sizeToFit];
  138. if(self.label.frame.size.width>label.frame.size.width||self.label.frame.size.height>label.frame.size.height)
  139. {
  140. FullyShowViewController *fullVC = [[UIStoryboard storyboardWithName:@"Result" bundle:nil] instantiateViewControllerWithIdentifier:@"fullyShowViewController"];
  141. fullVC.htmlText = label.htmlText;
  142. fullVC.preferredContentSize = CGSizeMake(200, 240);
  143. fullVC.modalPresentationStyle=UIModalPresentationPopover;
  144. UIPopoverPresentationController* popPc = fullVC.popoverPresentationController;
  145. popPc.permittedArrowDirections = UIPopoverArrowDirectionAny;
  146. CGRect rectl = [RAUtils relativeFrameForScreenWithView:label];
  147. CGRect rectv =[RAUtils relativeFrameForScreenWithView:self.view];
  148. CGRect intersection_rect=CGRectIntersection(rectl, rectv);
  149. UIWindow * window=[[[UIApplication sharedApplication] delegate] window];
  150. CGRect source_rect=[RAUtils relativeFrame:intersection_rect FromView:window toView:label];
  151. // CGRect rect=[v convertRect: v.bounds toView:window];
  152. popPc.sourceRect = source_rect;
  153. popPc.sourceView = label;
  154. // popPc.barButtonItem = label;
  155. popPc.delegate = self;
  156. [self presentViewController:fullVC animated:true completion:nil];
  157. }
  158. }
  159. - (void)didReceiveMemoryWarning {
  160. [super didReceiveMemoryWarning];
  161. // Dispose of any resources that can be recreated.
  162. }
  163. //- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
  164. //
  165. //}
  166. //-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
  167. //{
  168. // // auto resizing
  169. //// self.scrollview.contentSize=self.tableview.frame.size;
  170. //
  171. // // auto layout
  172. //// int width=[self.content_layout[@"header"][@"width"] intValue];
  173. //// if(width<self.view.frame.size.width)
  174. //// width=self.view.frame.size.width;
  175. //// self.w_constraint.constant = width - CGRectGetWidth(self.view.bounds);
  176. //// self.h_constraint.constant = 0;
  177. // [self updateTableFrame];
  178. //
  179. //}
  180. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
  181. __weak typeof(self) weakSelf = self;
  182. [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
  183. // 动画前
  184. } completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
  185. // 动画后
  186. [weakSelf updateTableFrame];
  187. }];
  188. [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
  189. }
  190. #pragma mark - TableView DataSource
  191. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  192. return [self.content_data[@"count"] intValue];
  193. // return 0;
  194. }
  195. //- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  196. //{
  197. // return 1;
  198. //}
  199. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  200. {
  201. int height=[self.content_layout[@"header"][@"height"] intValue];
  202. if(height==0)
  203. height=44;
  204. return height;
  205. }
  206. - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  207. {
  208. NSArray* arr_col=self.content_layout[@"header"][@"col"];
  209. NSString* value =self.content_layout[@"header"][@"f_color"];//[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  210. if(value==nil)
  211. value=@"";
  212. unsigned long fcolor = strtoul([value UTF8String],0,16);
  213. value =self.content_layout[@"header"][@"bg_color"];//[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  214. if(value==nil)
  215. value=@"0xFFFFFF";
  216. unsigned long bgcolor = strtoul([value UTF8String],0,16);
  217. UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  218. myView.backgroundColor = UIColorFromRGB(bgcolor);
  219. myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
  220. myView.layer.shadowColor = [UIColor blackColor].CGColor;
  221. myView.layer.shadowOffset = CGSizeMake(0, 0);
  222. myView.layer.shadowOpacity = 0.5;
  223. myView.layer.shadowRadius = 2.0;
  224. int x=0;//[self.content_layout[@"header"][@"margin_l"] intValue];
  225. int y=0;//[self.content_layout[@"header"][@"margin_t"] intValue];;
  226. int height = [self.content_layout[@"header"][@"height"] intValue];
  227. for(int i=0;i<arr_col.count;i++)
  228. {
  229. int width = [arr_col[i][@"width"] intValue];
  230. UILabel *headerlabel = [[UILabel alloc] initWithFrame:CGRectMake(x, y, width, height)];
  231. headerlabel.font = [UIFont boldSystemFontOfSize:self.default_title_text_size];
  232. headerlabel.textColor=UIColorFromRGB(fcolor);//UIColor.blackColor;
  233. headerlabel.backgroundColor = [UIColor clearColor];
  234. headerlabel.text=arr_col[i][@"name"];
  235. headerlabel.textAlignment= [self get_TextHAlign:arr_col[i][@"h_align"] ];
  236. // headerlabel.font = [UIFont boldSystemFontOfSize:20];
  237. // [headerlabel sizeToFit];
  238. headerlabel.layer.borderWidth=0.5;
  239. headerlabel.layer.borderColor = UIColorFromRGB(self.default_line_color).CGColor;
  240. [myView addSubview:headerlabel];
  241. x+=width;
  242. }
  243. myView.autoresizesSubviews=true;
  244. // [myView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin];
  245. // modellabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  246. // pricelabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  247. // timelabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  248. myView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  249. //
  250. return myView;
  251. }
  252. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  253. {
  254. int height=[self.content_layout[@"row"][@"height"] intValue];
  255. if(height==0)
  256. height=44;
  257. return height;
  258. }
  259. -(NSTextAlignment) get_TextHAlign:(NSString*)textHAlign
  260. {
  261. if([textHAlign.lowercaseString isEqualToString:@"center"])
  262. return NSTextAlignmentCenter;
  263. else if([textHAlign.lowercaseString isEqualToString:@"left"])
  264. return NSTextAlignmentLeft;
  265. else if([textHAlign.lowercaseString isEqualToString:@"right"])
  266. return NSTextAlignmentRight;
  267. return NSTextAlignmentLeft;
  268. }
  269. //-(RTTextAlignment) get_RTTextHAlign:(NSString*)textHAlign
  270. //{
  271. //
  272. //
  273. //
  274. //
  275. // if([textHAlign.lowercaseString isEqualToString:@"center"])
  276. // return RTTextAlignmentCenter;
  277. // else if([textHAlign.lowercaseString isEqualToString:@"left"])
  278. // return RTTextAlignmentLeft;
  279. // else if([textHAlign.lowercaseString isEqualToString:@"right"])
  280. // return RTTextAlignmentRight;
  281. //
  282. // return RTTextAlignmentLeft;
  283. //}
  284. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  285. {
  286. {
  287. NSString *CellIdentifier = @"tCell";
  288. ResultCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  289. cell.touchDelegate = self;
  290. for(UIGestureRecognizer* g in cell.gestureRecognizers)
  291. [ cell removeGestureRecognizer:g];
  292. // cell gesture
  293. // [cell removeGestureRecognizer:self.cellDoubleTap];
  294. for(UIView* v in cell.subviews)
  295. {
  296. for(UIGestureRecognizer* g in v.gestureRecognizers)
  297. [ v removeGestureRecognizer:g];
  298. [v removeFromSuperview];
  299. }
  300. // cell.detailTextLabel.text=@"detail";
  301. // cell.textLabel.text=[NSString stringWithFormat:@"%ld",indexPath.row];
  302. UITapGestureRecognizer *cellDoubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cellDoubleTapAction:)];
  303. cellDoubleTap.numberOfTouchesRequired = 1; //手指数
  304. cellDoubleTap.numberOfTapsRequired = 2; //tap次数
  305. [cell addGestureRecognizer:cellDoubleTap];
  306. // 3D Touch
  307. // if (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable) {
  308. // DebugLog(@"3D Touch 可用!");
  309. // //给cell注册3DTouch的peek(预览)和pop功能
  310. // [self registerForPreviewingWithDelegate:self sourceView:cell];
  311. // } else {
  312. // DebugLog(@"3D Touch 无效");
  313. // }
  314. NSArray* arr_col=self.content_layout[@"header"][@"col"];
  315. NSArray* item =self.content_data[[NSString stringWithFormat:@"item_%ld",indexPath.row]];
  316. NSString* value =self.content_layout[@"row"][@"f_color"];//[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  317. if(value==nil)
  318. value=@"";
  319. unsigned long fcolor = strtoul([value UTF8String],0,16);
  320. value =self.content_layout[@"row"][@"color_0"];//[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  321. if(value==nil)
  322. value=@"";
  323. unsigned long color0 = strtoul([value UTF8String],0,16);
  324. value =self.content_layout[@"row"][@"color_1"];//[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  325. if(value==nil)
  326. value=@"";
  327. unsigned long color1 = strtoul([value UTF8String],0,16);
  328. int x=0;//[self.content_layout[@"header"][@"margin_l"] intValue];
  329. int y=0;//[self.content_layout[@"header"][@"margin_t"] intValue];;
  330. int height = [self.content_layout[@"row"][@"height"] intValue];
  331. for(int i=0;i<arr_col.count;i++)
  332. {
  333. int width = [arr_col[i][@"width"] intValue];;
  334. MDHTMLLabel *vallabel = [[MDHTMLLabel alloc] initWithFrame:CGRectMake(x, y, width, height)];
  335. vallabel.textInsets = UIEdgeInsetsMake(0.f, 8.f, 0.f, 8.f);
  336. vallabel.font = [UIFont systemFontOfSize:self.default_row_text_size];
  337. vallabel.textColor=UIColorFromRGB(fcolor);//UIColor.blackColor;
  338. vallabel.backgroundColor = [UIColor clearColor];
  339. NSString* text=@"";
  340. if(i>item.count-1)
  341. text=@"row data missing";
  342. else
  343. text=item[i];
  344. // RTTextLineBreakModeWordWrapping = kCTLineBreakByWordWrapping,
  345. // RTTextLineBreakModeCharWrapping = kCTLineBreakByCharWrapping,
  346. // RTTextLineBreakModeClip = kCTLineBreakByClipping,
  347. // NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:text];
  348. // vallabel.attributedText = attrStr;
  349. vallabel.htmlText = text;
  350. vallabel.textAlignment= [self get_TextHAlign:arr_col[i][@"h_align"] ];
  351. vallabel.layer.borderWidth=0.3;
  352. vallabel.layer.borderColor = UIColorFromRGB(self.default_line_color).CGColor;
  353. // UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(labelTapAction:)];
  354. UITapGestureRecognizer* labelTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelTapAction:)];
  355. labelTap.numberOfTouchesRequired = 1; //手指数
  356. labelTap.numberOfTapsRequired = 1; //tap次数
  357. [vallabel addGestureRecognizer:labelTap];
  358. [labelTap requireGestureRecognizerToFail:cellDoubleTap];
  359. // [vallabel addGestureRecognizer:self.cellDoubleTap];
  360. vallabel.userInteractionEnabled = YES;
  361. // [vallabel becomeFirstResponder];
  362. // vallabel.delegate = self;
  363. // [statuslabel sizeToFit];
  364. [cell addSubview:vallabel];
  365. x+=width;
  366. }
  367. cell.touchColor = [UIColor colorWithRed:0.3 green:0.3 blue:0.3 alpha:0.4];
  368. // cell.contentView.backgroundColor = [UIColor redColor];
  369. if(indexPath.row%2==0)
  370. cell.backgroundColor=UIColorFromRGB(color0);//[UIColor whiteColor];
  371. else
  372. cell.backgroundColor=UIColorFromRGB(color1);//[UIColor lightGrayColor];
  373. return cell;
  374. }
  375. }
  376. //- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  377. //// cell.backgroundColor = [UIColor whiteColor];
  378. //}
  379. //#pragma mark - TouchLabel Delegate
  380. //- (void)touchLabel:(TouchLabel *)touchLabel touchesWtihTag:(NSInteger)tag
  381. //{
  382. //
  383. //}
  384. //-(void) empty
  385. //{
  386. //
  387. //}
  388. #pragma mark - UIPopoverPresentationControllerDelegate Delegate
  389. //实现该代理方法,返回UIModalPresentationNone值,可以在iPhone设备实现popover效果
  390. -(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller{
  391. return UIModalPresentationNone;//不适配(不区分ipad或iPhone)
  392. }
  393. #pragma mark - TableView Delegate
  394. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  395. {
  396. NSLog(@"cell selected");
  397. }
  398. - (UITableViewCellEditingStyle)tableView:(UITableView *)tv editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
  399. return UITableViewCellEditingStyleDelete;
  400. }
  401. #pragma mark - Public
  402. - (void)setQueryParams:(NSMutableDictionary *)params {
  403. self.params = params;
  404. }
  405. #pragma mark - Private
  406. - (void)setupTableRefreshView {
  407. __weak typeof(self) weakSelf = self;
  408. self.tableview.jl_header = [[JLRefreshHeader alloc] init];
  409. self.tableview.jl_header.refreshDelegate = self;
  410. self.tableview.jl_header.clear = YES;
  411. self.tableview.jl_header.offsetBlock = ^(CGFloat offset) {
  412. if (offset <= 0) {
  413. weakSelf.header_top_constraint.constant = -offset;
  414. }
  415. };
  416. self.tableview.jl_header.stateChangeBlock = ^(JLRefreshState state) {
  417. NSString *title = [weakSelf.tableview.jl_header refreshTitleForState:state];
  418. weakSelf.refreshHeaderTitleLb.text = title;
  419. };
  420. self.tableview.jl_footer = [[JLRefreshFooter alloc] init];
  421. self.tableview.jl_footer.refreshDelegate = self;
  422. self.tableview.jl_footer.clear = YES;
  423. self.tableview.jl_footer.offsetBlock = ^(CGFloat offset) {
  424. if (offset <= 0) {
  425. weakSelf.footer_top_constraint.constant = offset;
  426. }
  427. };
  428. self.tableview.jl_footer.stateChangeBlock = ^(JLRefreshState state) {
  429. NSString *title = [weakSelf.tableview.jl_footer refreshTitleForState:state];
  430. weakSelf.refreshFooterTitleLb.text = title;
  431. };
  432. }
  433. - (void)configureTableView {
  434. [self.tableview registerNib:[UINib nibWithNibName:@"ResultCell" bundle:nil] forCellReuseIdentifier:@"tCell"];
  435. }
  436. - (void)setupNavigationBar {
  437. if(self.content_menu==nil)
  438. {
  439. self.navigationItem.rightBarButtonItem=nil;
  440. return;
  441. }
  442. UIBarButtonItem *menuItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"ic_menu"] style:UIBarButtonItemStylePlain target:self action:@selector(MenuClick:)];
  443. self.navigationItem.rightBarButtonItem = menuItem;
  444. UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
  445. backItem.title = @"Back";
  446. self.navigationItem.backBarButtonItem = backItem;
  447. }
  448. - (NSInteger)resultItemCount {
  449. return [[self.content_data objectForKey:@"count"] integerValue];
  450. }
  451. - (void)loadContent {
  452. [self loadContentWithOption:0 Complete:nil];
  453. }
  454. - (void)updateTableFrame {
  455. // auto resizing
  456. // int width=[self.content_layout[@"header"][@"width"] intValue];
  457. // if(width<self.tableview.frame.size.width)
  458. // width=self.tableview.frame.size.width;
  459. //
  460. // CGRect frame = CGRectMake(self.tableview.frame.origin.x, self.tableview.frame.origin.y, width, self.tableview.frame.size.height);
  461. // self.tableview.frame=frame;
  462. // self.scrollview.contentSize=self.tableview.frame.size;
  463. // auto layout
  464. int width=[self.content_layout[@"header"][@"width"] intValue];
  465. if(width<self.view.frame.size.width)
  466. width=self.view.frame.size.width;
  467. self.w_constraint.constant = width - CGRectGetWidth(self.view.bounds);
  468. self.h_constraint.constant = 0;
  469. // 约束修改后立即重新布局
  470. [self.view layoutIfNeeded];
  471. if (@available(iOS 11.0,*)) {
  472. UIEdgeInsets edgeInsets = [self.view safeAreaInsets];
  473. CGFloat left = edgeInsets.left;
  474. CGFloat right = edgeInsets.right;
  475. self.lead_constraint.constant = left;
  476. self.trail_constraint.constant = right;
  477. /*
  478. * lead 和 trail改变之前
  479. * scrollview.size.width = self.view.size.width;
  480. * 改变后
  481. * scrollview.size.width = self.view.size.width - left - right;
  482. * 由于w_contraint本质上是根据scrolliew.size.width决定,实际上使用self.view.size.width计算得到
  483. * 所以w_contraint需要 +left +right补偿偏差。
  484. */
  485. self.w_constraint.constant += left + right;
  486. // 约束修改后立即重新布局
  487. [self.view layoutIfNeeded];
  488. }
  489. }
  490. #pragma mark - RefreshDelegate
  491. - (void)jl_pullRefresh:(JLRefreshBasis *)refresh state:(JLRefreshState)state percentage:(float)percentage {
  492. // NSString *title = [refresh refreshTitleForState:state];
  493. // CGFloat offset = refresh.jl_height * percentage;
  494. if ([refresh isEqual:self.tableview.jl_header]) {
  495. // self.refreshHeaderTitleLb.text = title;
  496. // self.header_top_constraint.constant = offset;
  497. }
  498. if (refresh == self.tableview.jl_footer) {
  499. // self.refreshFooterTitleLb.text = title;
  500. // self.footer_top_constraint.constant = -offset;
  501. }
  502. }
  503. - (void)jl_endRefresh:(JLRefreshBasis *)refresh {
  504. // state == idle
  505. // // refresh UI
  506. // [self.tableview reloadData];
  507. if (refresh == self.tableview.jl_footer && refresh.state == JLRefreshStateNoMore) {
  508. }
  509. }
  510. - (void)jl_beginRefresh:(JLRefreshBasis *)refresh {
  511. // state == refreshing
  512. // load data
  513. // finish loading data
  514. int option = 0;
  515. if ([refresh isEqual:self.tableview.jl_header]) {
  516. option = 1;
  517. }
  518. if (refresh == self.tableview.jl_footer) {
  519. if(refresh.state==JLRefreshStateNoMore) //数据取完不再加载
  520. return;
  521. option = 2;
  522. }
  523. self.tableview.userInteractionEnabled = NO;
  524. __weak typeof(self) weakSelf = self;
  525. [self loadContentWithOption:option Complete:^(int result, int count) {
  526. weakSelf.tableview.userInteractionEnabled = YES;
  527. if ([refresh isEqual:weakSelf.tableview.jl_header]) {
  528. [weakSelf.tableview.jl_header performSelector:@selector(endRefresh)];
  529. }
  530. if (refresh == weakSelf.tableview.jl_footer) {
  531. [weakSelf.tableview.jl_footer performSelector:@selector(endRefresh)];
  532. if (result == 2 && count < delta) {
  533. [weakSelf.tableview.jl_footer performSelector:@selector(noMoreData)];
  534. }
  535. }
  536. }];
  537. }
  538. #pragma mark - Quick Look
  539. - (MyQLPreviewController *)quickLook {
  540. if (!_quickLook)
  541. {
  542. _quickLook = [[MyQLPreviewController alloc] init];
  543. _quickLook.delegate = self;
  544. _quickLook.dataSource = self;
  545. }
  546. else
  547. {
  548. [_quickLook reloadData];
  549. }
  550. return _quickLook;
  551. }
  552. #pragma mark - QuickLook Data Source
  553. - (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller {
  554. return 1;
  555. }
  556. - (id <QLPreviewItem>) previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index {
  557. if(self.documentPath==nil)
  558. return nil;
  559. return [NSURL fileURLWithPath:self.documentPath];
  560. }
  561. #pragma mark - QuickLook Delegate
  562. - (void) previewControllerDidDismiss:(QLPreviewController *)controller {
  563. }
  564. /**
  565. * 文件内部链接点击不进行外部跳转
  566. */
  567. - (BOOL) previewController:(QLPreviewController *)controller shouldOpenURL:(NSURL *)url forPreviewItem:(id<QLPreviewItem>)item {
  568. return NO;
  569. }
  570. #pragma mark - customize editor
  571. - (UIView*)get_tableHeader
  572. {
  573. UILabel * headerview = [UILabel new];
  574. headerview.frame = CGRectMake(0, 0, self.tableview.frame.size.width, 44);
  575. headerview.numberOfLines = 0;
  576. headerview.textAlignment = NSTextAlignmentCenter;
  577. headerview.text = @"";
  578. return headerview;
  579. }
  580. -(void) resize_tableHeader
  581. {
  582. //利用systemLayoutSizeFittingSize:计算出真实高度
  583. CGFloat height = [self.tableview.tableHeaderView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
  584. CGRect headerFrame = self.tableview.tableHeaderView.frame;
  585. headerFrame.size.height = height+20;//20是留的上下边距
  586. //修改tableHeaderView的frame
  587. self.tableview.tableHeaderView.frame = headerFrame;
  588. }
  589. #pragma mark - 3D Touch Delegate (PreviewingDelegate)
  590. // peek (预览)
  591. - (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location {
  592. // [previewingContext sourceView]即为所按压的视图
  593. // UITableViewCell *view = (UITableViewCell *)[previewingContext sourceView];
  594. //
  595. // // 设置不被虚化的范围
  596. // CGRect rect = view.bounds;
  597. // [previewingContext setSourceRect:rect];
  598. //
  599. // NSIndexPath *indexPath = [self.tableview indexPathForCell:view];
  600. // // peek (预览界面)
  601. // UIViewController *tvc = [self viewControllerFor3DTouch:indexPath];
  602. //
  603. // tvc.preferredContentSize = CGSizeMake(0, 480); // 预览图的大小
  604. //
  605. // return tvc;
  606. // NSIndexPath *indexPath = [self.tableview indexPathForCell:view];
  607. // [self presses3DTouchForIndexPath:indexPath];
  608. return nil;
  609. }
  610. // pop (在预览基础上更用力按压)
  611. - (void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit {
  612. // [self showViewController:viewControllerToCommit sender:self];
  613. }
  614. #pragma mark - Cell Touch Delegate
  615. - (void)touchedCell:(ResultCell *)cell withForce:(float)force {
  616. if (force > 4.0f) {
  617. // 1519: 普通短震,3D Touch 中 Peek 震动反馈
  618. // 1520: 普通短震,3D Touch 中 Pop 震动反馈
  619. // 1521: 连续三次短震
  620. // kSystemSoundID_Vibrate: 震动很暴力,不适合震动反馈
  621. AudioServicesPlaySystemSound(1519); // 支持震动的设备上会震动,不支持就什么都不做 kSystemSoundID_Vibrate
  622. NSIndexPath *indexPath = [self.tableview indexPathForCell:cell];
  623. [self presses3DTouchForIndexPath:indexPath];
  624. }
  625. NSLog(@"force %f",force);
  626. }
  627. #pragma mark - Child View Controller Override
  628. /**
  629. * 0: init load
  630. * 1: refresh
  631. * 2: load more
  632. */
  633. - (void)loadContentWithOption:(int)option Complete:(void (^)(int result,int count))finish {
  634. NSAssert(true, ([NSString stringWithFormat:@"%s loadContentWithOption not impl",object_getClassName([self class])]));
  635. // if (self.params) {
  636. //
  637. // NSMutableDictionary *dic = self.params.mutableCopy;
  638. // switch (option) {
  639. // case 0:
  640. // case 1: {
  641. // self.offset = 0;
  642. // self.content_layout =nil;
  643. // self.content_action = nil;
  644. // self.content_menu = nil;
  645. // self.content_data = nil;
  646. // }
  647. // break;
  648. // case 2: {
  649. // self.offset = [self resultItemCount];
  650. // }
  651. // break;
  652. // }
  653. //
  654. //// dic[@"criteria"] = self.params;
  655. //
  656. // [dic setObject:@(self.offset) forKey:@"offset"];
  657. // [dic setObject:@(delta) forKey:@"limit"];
  658. //// dic[@"criteria"] = [NSArray arrayWithObjects:@"aaa",@"bbb", nil];
  659. //
  660. // __weak typeof(self) weakSelf = self;
  661. // dispatch_async(dispatch_get_global_queue(0, 0), ^{
  662. // NSDictionary *contentDic = [RANetwork query:dic];
  663. // NSInteger result = [[contentDic objectForKey:@"result"] integerValue];
  664. // dispatch_async(dispatch_get_main_queue(), ^{
  665. // if (weakSelf) {
  666. // __strong typeof(weakSelf) strongSelf = weakSelf;
  667. // if (result == RESULT_TRUE) {
  668. // strongSelf.content_layout = [contentDic objectForKey:@"layout"];
  669. // strongSelf.content_action = [contentDic objectForKey:@"row_action"];
  670. // strongSelf.content_menu = [[contentDic objectForKey:@"menu"] mutableCopy];
  671. // [strongSelf setupNavigationBar];
  672. //
  673. // UILabel * headerview=(UILabel *)self.tableview.tableHeaderView;
  674. // headerview.text = contentDic[@"table_title"];
  675. // [self resize_tableHeader];
  676. //
  677. // if(strongSelf.content_data==nil)
  678. // strongSelf.content_data = [NSMutableDictionary new];
  679. // NSMutableDictionary* newdata = [[contentDic objectForKey:@"data"] mutableCopy];
  680. // for(int dc = 0;dc<[newdata[@"count"] intValue];dc++)
  681. // {
  682. // NSMutableDictionary * newdata_item = newdata[[NSString stringWithFormat:@"item_%d",dc]];
  683. //
  684. // strongSelf.content_data[[NSString stringWithFormat:@"item_%d",[strongSelf.content_data[@"count"] intValue] ]] = newdata_item;
  685. // strongSelf.content_data[@"count"] = @([strongSelf.content_data[@"count"] intValue]+1);
  686. // }
  687. //
  688. //// strongSelf.content_data = [contentDic objectForKey:@"data"];
  689. // [strongSelf updateTableFrame];
  690. // [strongSelf.tableview reloadData];
  691. // } else {
  692. // [RAUtils message_alert:[contentDic objectForKey:@"err_msg"] title:@"Warning" controller:strongSelf];
  693. // }
  694. //
  695. // if (finish) {
  696. // finish((int)result,(int)[self resultItemCount]);
  697. // }
  698. //
  699. // }
  700. //
  701. // });
  702. // });
  703. // }
  704. }
  705. - (void)MenuClick:(UIBarButtonItem *)sender {
  706. // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  707. // //block代码块取代了delegate
  708. //
  709. // __weak typeof(self) weakSelf = self;
  710. // for(int i=0;i<self.content_menu.count;i++)
  711. // {
  712. // NSMutableDictionary* json = self.content_menu[i];
  713. // NSString* title =json[@"title"];
  714. // NSString* actiontype = json[@"action"];
  715. // NSString* url = json[@"url"];
  716. //// NSMutableDictionary* add_params = json[@"params"];
  717. // UIAlertAction *actioni = [UIAlertAction actionWithTitle:title style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  718. // // DebugLog(@"Cancel");
  719. // if([actiontype isEqualToString:@"download"])
  720. // {
  721. // [weakSelf Export:url];
  722. // }
  723. // else if([actiontype isEqualToString:@"save"])
  724. // {
  725. // [weakSelf save];
  726. // }
  727. // }];
  728. // [alertControl addAction:actioni];
  729. // }
  730. //
  731. // UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  732. // // DebugLog(@"Cancel");
  733. //
  734. // }];
  735. // [alertControl addAction:actionCancel];
  736. //
  737. //
  738. //
  739. //
  740. //
  741. // [self presentViewController:alertControl animated:NO completion:nil];
  742. }
  743. //- (void)save {
  744. //
  745. //}
  746. //
  747. //-(void)Export:(NSString*) url
  748. //{
  749. //
  750. // NSAssert(true, ([NSString stringWithFormat:@"%s Export not impl",object_getClassName([self class])]));
  751. //// if(self.download_query )
  752. //// {
  753. //// self.documentPath = self.download_query;
  754. //// [self.navigationController pushViewController:self.quickLook animated:NO];
  755. //// return;
  756. //// }
  757. ////
  758. //// __weak typeof(self) weakSelf = self;
  759. //// dispatch_async(dispatch_get_global_queue(0, 0), ^{
  760. ////
  761. ////// NSMutableDictionary *params = self.params.mutableCopy;
  762. ////// if(add_params!=nil)
  763. ////// [params addEntriesFromDictionary:add_params];
  764. //// NSString *path = [RANetwork download_query:url];
  765. //// weakSelf.download_query = path;
  766. //// weakSelf.documentPath = path;
  767. ////
  768. //// if (path) {
  769. //// dispatch_async(dispatch_get_main_queue(), ^{
  770. //// [weakSelf.navigationController pushViewController:weakSelf.quickLook animated:NO];
  771. //// });
  772. //// }
  773. ////
  774. //// });
  775. //}
  776. //- (void)downloadItemClick:(UIBarButtonItem *)sender {
  777. // NSAssert(true, ([NSString stringWithFormat:@"%s downloadItemClick not impl",object_getClassName([self class])]));
  778. ////
  779. ////
  780. //// if(self.download_query )
  781. //// {
  782. //// self.documentPath = self.download_query;
  783. //// [self.navigationController pushViewController:self.quickLook animated:NO];
  784. //// return;
  785. //// }
  786. ////
  787. //// __weak typeof(self) weakSelf = self;
  788. //// dispatch_async(dispatch_get_global_queue(0, 0), ^{
  789. ////
  790. //// NSMutableDictionary *params = self.params.mutableCopy;
  791. //// NSString *path = [RANetwork download_query:params];
  792. //// weakSelf.download_query = path;
  793. //// weakSelf.documentPath = path;
  794. ////
  795. //// if (path) {
  796. //// dispatch_async(dispatch_get_main_queue(), ^{
  797. //// [weakSelf.navigationController pushViewController:weakSelf.quickLook animated:NO];
  798. //// });
  799. //// }
  800. ////
  801. //// });
  802. ////
  803. //}
  804. - (void)presses3DTouchForIndexPath:(NSIndexPath *)indexPath {
  805. }
  806. -(void)cellDoubleTapAction:(UIGestureRecognizer*)gestureRecognizer
  807. {
  808. NSAssert(true, ([NSString stringWithFormat:@"%s cellDoubleTapAction not impl",object_getClassName([self class])]));
  809. }
  810. //{
  811. // NSLog(@"cell double tap");
  812. // UITableViewCell* cell = (UITableViewCell*)[gestureRecognizer view];
  813. // NSIndexPath* indexPath=[self.tableview indexPathForCell:cell];
  814. // //strongSelf.content_action
  815. // if(self.content_action!=nil)
  816. // {
  817. //
  818. // if(self.content_action.count==1)
  819. // {
  820. // NSDictionary* action =self.content_action.firstObject;
  821. // NSString * module = action[@"module"];
  822. // if([module isEqualToString:@"quick_look"])
  823. // {
  824. //
  825. // // +(NSString*)download_file : (NSMutableDictionary*) params url:(NSString*) url
  826. // NSMutableDictionary *params = action[@"params"];
  827. // NSString* URL =action[@"url"];
  828. // __weak typeof(self) weakSelf = self;
  829. // dispatch_async(dispatch_get_global_queue(0, 0), ^{
  830. //
  831. //
  832. // NSString *path = [RANetwork download_file:params url:URL];
  833. // weakSelf.documentPath = path;
  834. //
  835. // if (path) {
  836. // dispatch_async(dispatch_get_main_queue(), ^{
  837. // [weakSelf.navigationController pushViewController:weakSelf.quickLook animated:NO];
  838. // });
  839. // }
  840. //
  841. // });
  842. // }
  843. // else if([module isEqualToString:@"kv_detail"])
  844. // {
  845. // NSMutableDictionary *params = [NSMutableDictionary new];
  846. // params[@"query_id"] = self.params[@"query_id"];
  847. //
  848. // NSMutableDictionary *criteria =[NSMutableDictionary new];
  849. // for(NSString* key in [action[@"params"] allKeys] )
  850. // {
  851. // NSArray* item =self.content_data[[NSString stringWithFormat:@"item_%ld",indexPath.row]];
  852. // int idx =[action[@"params"][key] intValue];
  853. // criteria[key]=item[ idx];
  854. // }
  855. //
  856. //
  857. // params[@"criteria"]=[RAConvertor dict2string:criteria] ;
  858. //
  859. //
  860. //
  861. // UIAlertView * waitalert = [RAUtils waiting_alert:@"Loading..." title:@"Please wait"];
  862. //
  863. //
  864. // __weak typeof(self) weakself = self;
  865. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  866. //
  867. //
  868. //
  869. // NSDictionary* json =[RANetwork kv_detail:params];
  870. //
  871. // dispatch_async(dispatch_get_main_queue(), ^{
  872. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  873. //
  874. //
  875. // if([[json valueForKey:@"result"] intValue]==2)
  876. // {
  877. // KVViewController *vc = [[UIStoryboard storyboardWithName:@"Detail" bundle:nil] instantiateViewControllerWithIdentifier:@"KVViewController"];
  878. // vc.content = [json mutableCopy];
  879. // [weakself.navigationController pushViewController:vc animated:NO];
  880. //
  881. // // weakself.content_data_download = [weakself CopyDirty:weakself.content_data_download to:[editor_json mutableCopy]];//[editor_json mutableCopy];
  882. // //
  883. // // weakself.content_data_control = [weakself translate_json:weakself.content_data_download changed: weakself.changed_data];
  884. // //
  885. // //
  886. // // [weakself download_success];
  887. // // [weakself.editorTable reloadData];
  888. //
  889. // }
  890. // else
  891. // {
  892. // [RAUtils message_alert:json[@"msg"] title:nil controller:weakself] ;
  893. // }
  894. //
  895. //
  896. //
  897. //
  898. // });
  899. // });
  900. // }
  901. // else if([module isEqualToString:@"order_detail"])
  902. // {
  903. //
  904. // OrderDetailViewController *vc = [[UIStoryboard storyboardWithName:@"Detail" bundle:nil] instantiateViewControllerWithIdentifier:@"OrderDetailViewController"];
  905. //
  906. //
  907. // vc.url_type = URL_REMOTE;
  908. // vc.request_url=URL_ORDER_DETAIL;
  909. //
  910. //
  911. // vc.params = [NSMutableDictionary dictionary];
  912. // // NSString *path = [[NSBundle mainBundle] pathForResource:@"search_ui.json" ofType:nil];
  913. // // NSData *data = [NSData dataWithContentsOfFile:path];
  914. // // vc.content_data_download = [[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil] mutableCopy];
  915. // [self.navigationController pushViewController:vc animated:NO];
  916. // return;
  917. // }
  918. // }
  919. // else
  920. // {
  921. //
  922. // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"" message:nil preferredStyle:UIAlertControllerStyleAlert];
  923. // //block代码块取代了delegate
  924. //
  925. // __weak typeof(self) weakSelf = self;
  926. // for(int i=0;i<self.content_action.count;i++)
  927. // {
  928. // NSMutableDictionary* json = self.content_action[i];
  929. // NSString* title =json[@"title"];
  930. // NSString* module = json[@"module"];
  931. // NSMutableDictionary* add_params = json[@"params"];
  932. // UIAlertAction *actioni = [UIAlertAction actionWithTitle:title style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  933. //
  934. //
  935. // if([module isEqualToString:@"quick_look"])
  936. // {
  937. //
  938. // // +(NSString*)download_file : (NSMutableDictionary*) params url:(NSString*) url
  939. // NSMutableDictionary *params = json[@"params"];
  940. // NSString* URL =json[@"url"];
  941. // __weak typeof(self) weakSelf = self;
  942. // dispatch_async(dispatch_get_global_queue(0, 0), ^{
  943. //
  944. //
  945. // NSString *path = [RANetwork download_file:params url:URL];
  946. // weakSelf.documentPath = path;
  947. //
  948. // if (path) {
  949. // dispatch_async(dispatch_get_main_queue(), ^{
  950. // [weakSelf.navigationController pushViewController:weakSelf.quickLook animated:NO];
  951. // });
  952. // }
  953. //
  954. // });
  955. // }
  956. // else if([module isEqualToString:@"kv_detail"])
  957. // {
  958. // NSMutableDictionary *params = json[@"params"];
  959. //
  960. //
  961. // UIAlertView * waitalert = [RAUtils waiting_alert:@"Loading..." title:@"Please wait"];
  962. //
  963. //
  964. // __weak typeof(self) weakself = self;
  965. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  966. //
  967. //
  968. //
  969. // NSDictionary* json =[RANetwork kv_detail:params];
  970. //
  971. // dispatch_async(dispatch_get_main_queue(), ^{
  972. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  973. //
  974. //
  975. // if([[json valueForKey:@"result"] intValue]==2)
  976. // {
  977. // KVViewController *vc = [[UIStoryboard storyboardWithName:@"Detail" bundle:nil] instantiateViewControllerWithIdentifier:@"KVViewController"];
  978. // vc.content = [json mutableCopy];
  979. // [weakself.navigationController pushViewController:vc animated:NO];
  980. //
  981. // // weakself.content_data_download = [weakself CopyDirty:weakself.content_data_download to:[editor_json mutableCopy]];//[editor_json mutableCopy];
  982. // //
  983. // // weakself.content_data_control = [weakself translate_json:weakself.content_data_download changed: weakself.changed_data];
  984. // //
  985. // //
  986. // // [weakself download_success];
  987. // // [weakself.editorTable reloadData];
  988. //
  989. // }
  990. // else
  991. // {
  992. // [RAUtils message_alert:json[@"msg"] title:nil controller:weakself] ;
  993. // }
  994. //
  995. //
  996. //
  997. //
  998. // });
  999. // });
  1000. // }
  1001. // else if([module isEqualToString:@"order_detail"])
  1002. // {
  1003. //
  1004. // OrderDetailViewController *vc = [[UIStoryboard storyboardWithName:@"Detail" bundle:nil] instantiateViewControllerWithIdentifier:@"OrderDetailViewController"];
  1005. //
  1006. //
  1007. // vc.url_type = URL_REMOTE;
  1008. // vc.request_url=URL_ORDER_DETAIL;
  1009. //
  1010. //
  1011. // vc.params = [NSMutableDictionary dictionary];
  1012. // // NSString *path = [[NSBundle mainBundle] pathForResource:@"search_ui.json" ofType:nil];
  1013. // // NSData *data = [NSData dataWithContentsOfFile:path];
  1014. // // vc.content_data_download = [[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil] mutableCopy];
  1015. // [self.navigationController pushViewController:vc animated:NO];
  1016. // return;
  1017. // }
  1018. // // DebugLog(@"Cancel");
  1019. //// if([actiontype isEqualToString:@"download"])
  1020. //// {
  1021. //// [weakSelf Export:add_params];
  1022. //// }
  1023. //// else if([actiontype isEqualToString:@"save"])
  1024. //// {
  1025. //// }
  1026. // }];
  1027. // [alertControl addAction:actioni];
  1028. // }
  1029. //
  1030. // UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1031. // // DebugLog(@"Cancel");
  1032. //
  1033. // }];
  1034. // [alertControl addAction:actionCancel];
  1035. //
  1036. //
  1037. //
  1038. //
  1039. //
  1040. // [self presentViewController:alertControl animated:NO completion:nil];
  1041. //
  1042. // }
  1043. //
  1044. // }
  1045. //
  1046. //
  1047. //
  1048. //}
  1049. @end