ResultViewController.m 43 KB

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