ResultViewController.m 47 KB

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