ResultViewController.m 45 KB

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