ResultViewController.m 47 KB

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