ResultViewController.m 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229
  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. - (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. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  598. cell.backgroundColor = [UIColor whiteColor];
  599. }
  600. //#pragma mark - TouchLabel Delegate
  601. //- (void)touchLabel:(TouchLabel *)touchLabel touchesWtihTag:(NSInteger)tag
  602. //{
  603. //
  604. //}
  605. //-(void) empty
  606. //{
  607. //
  608. //}
  609. #pragma mark - UIPopoverPresentationControllerDelegate Delegate
  610. //实现该代理方法,返回UIModalPresentationNone值,可以在iPhone设备实现popover效果
  611. -(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller{
  612. return UIModalPresentationNone;//不适配(不区分ipad或iPhone)
  613. }
  614. #pragma mark - TableView Delegate
  615. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  616. {
  617. NSLog(@"cell selected");
  618. }
  619. - (UITableViewCellEditingStyle)tableView:(UITableView *)tv editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
  620. return UITableViewCellEditingStyleDelete;
  621. }
  622. #pragma mark - Public
  623. - (void)setQueryParams:(NSDictionary *)params {
  624. self.params = params;
  625. }
  626. #pragma mark - Private
  627. - (void)setupTableRefreshView {
  628. __weak typeof(self) weakSelf = self;
  629. self.tableview.jl_header = [[JLRefreshHeader alloc] init];
  630. self.tableview.jl_header.refreshDelegate = self;
  631. self.tableview.jl_header.clear = YES;
  632. self.tableview.jl_header.offsetBlock = ^(CGFloat offset) {
  633. if (offset <= 0) {
  634. weakSelf.header_top_constraint.constant = -offset;
  635. }
  636. };
  637. self.tableview.jl_header.stateChangeBlock = ^(JLRefreshState state) {
  638. NSString *title = [weakSelf.tableview.jl_header refreshTitleForState:state];
  639. weakSelf.refreshHeaderTitleLb.text = title;
  640. };
  641. self.tableview.jl_footer = [[JLRefreshFooter alloc] init];
  642. self.tableview.jl_footer.refreshDelegate = self;
  643. self.tableview.jl_footer.clear = YES;
  644. self.tableview.jl_footer.offsetBlock = ^(CGFloat offset) {
  645. if (offset <= 0) {
  646. weakSelf.footer_top_constraint.constant = offset;
  647. }
  648. };
  649. self.tableview.jl_footer.stateChangeBlock = ^(JLRefreshState state) {
  650. NSString *title = [weakSelf.tableview.jl_footer refreshTitleForState:state];
  651. weakSelf.refreshFooterTitleLb.text = title;
  652. };
  653. }
  654. - (void)setupNavigationBar {
  655. if(self.content_menu==nil)
  656. {
  657. self.navigationItem.rightBarButtonItem=nil;
  658. return;
  659. }
  660. UIBarButtonItem *menuItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"ic_menu"] style:UIBarButtonItemStylePlain target:self action:@selector(MenuClick:)];
  661. self.navigationItem.rightBarButtonItem = menuItem;
  662. }
  663. - (void)MenuClick:(UIBarButtonItem *)sender {
  664. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"menu", nil) message:nil preferredStyle:UIAlertControllerStyleAlert];
  665. //block代码块取代了delegate
  666. __weak typeof(self) weakSelf = self;
  667. for(int i=0;i<self.content_menu.count;i++)
  668. {
  669. NSMutableDictionary* json = self.content_menu[i];
  670. NSString* title =json[@"title"];
  671. NSString* actiontype = json[@"action"];
  672. NSString* url = json[@"url"];
  673. // NSMutableDictionary* add_params = json[@"params"];
  674. UIAlertAction *actioni = [UIAlertAction actionWithTitle:title style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  675. // DebugLog(@"Cancel");
  676. if([actiontype isEqualToString:@"download"])
  677. {
  678. [weakSelf Export:url];
  679. }
  680. else if([actiontype isEqualToString:@"save"])
  681. {
  682. [weakSelf save];
  683. }
  684. }];
  685. [alertControl addAction:actioni];
  686. }
  687. UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  688. // DebugLog(@"Cancel");
  689. }];
  690. [alertControl addAction:actionCancel];
  691. [self presentViewController:alertControl animated:NO completion:nil];
  692. }
  693. - (void)save {
  694. }
  695. -(void)Export:(NSString*) url
  696. {
  697. NSAssert(true, ([NSString stringWithFormat:@"%s Export not impl",object_getClassName([self class])]));
  698. // if(self.download_query )
  699. // {
  700. // self.documentPath = self.download_query;
  701. // [self.navigationController pushViewController:self.quickLook animated:NO];
  702. // return;
  703. // }
  704. //
  705. // __weak typeof(self) weakSelf = self;
  706. // dispatch_async(dispatch_get_global_queue(0, 0), ^{
  707. //
  708. //// NSMutableDictionary *params = self.params.mutableCopy;
  709. //// if(add_params!=nil)
  710. //// [params addEntriesFromDictionary:add_params];
  711. // NSString *path = [RANetwork download_query:url];
  712. // weakSelf.download_query = path;
  713. // weakSelf.documentPath = path;
  714. //
  715. // if (path) {
  716. // dispatch_async(dispatch_get_main_queue(), ^{
  717. // [weakSelf.navigationController pushViewController:weakSelf.quickLook animated:NO];
  718. // });
  719. // }
  720. //
  721. // });
  722. }
  723. - (void)downloadItemClick:(UIBarButtonItem *)sender {
  724. NSAssert(true, ([NSString stringWithFormat:@"%s downloadItemClick not impl",object_getClassName([self class])]));
  725. //
  726. //
  727. // if(self.download_query )
  728. // {
  729. // self.documentPath = self.download_query;
  730. // [self.navigationController pushViewController:self.quickLook animated:NO];
  731. // return;
  732. // }
  733. //
  734. // __weak typeof(self) weakSelf = self;
  735. // dispatch_async(dispatch_get_global_queue(0, 0), ^{
  736. //
  737. // NSMutableDictionary *params = self.params.mutableCopy;
  738. // NSString *path = [RANetwork download_query:params];
  739. // weakSelf.download_query = path;
  740. // weakSelf.documentPath = path;
  741. //
  742. // if (path) {
  743. // dispatch_async(dispatch_get_main_queue(), ^{
  744. // [weakSelf.navigationController pushViewController:weakSelf.quickLook animated:NO];
  745. // });
  746. // }
  747. //
  748. // });
  749. //
  750. }
  751. - (NSInteger)resultItemCount {
  752. return [[self.content_data objectForKey:@"count"] integerValue];
  753. }
  754. - (void)loadContent {
  755. [self loadContentWithOption:0 Complete:nil];
  756. }
  757. /**
  758. * 0: init load
  759. * 1: refresh
  760. * 2: load more
  761. */
  762. - (void)loadContentWithOption:(int)option Complete:(void (^)(int result,int count))finish {
  763. NSAssert(true, ([NSString stringWithFormat:@"%s loadContentWithOption not impl",object_getClassName([self class])]));
  764. // if (self.params) {
  765. //
  766. // NSMutableDictionary *dic = self.params.mutableCopy;
  767. // switch (option) {
  768. // case 0:
  769. // case 1: {
  770. // self.offset = 0;
  771. // self.content_layout =nil;
  772. // self.content_action = nil;
  773. // self.content_menu = nil;
  774. // self.content_data = nil;
  775. // }
  776. // break;
  777. // case 2: {
  778. // self.offset = [self resultItemCount];
  779. // }
  780. // break;
  781. // }
  782. //
  783. //// dic[@"criteria"] = self.params;
  784. //
  785. // [dic setObject:@(self.offset) forKey:@"offset"];
  786. // [dic setObject:@(delta) forKey:@"limit"];
  787. //// dic[@"criteria"] = [NSArray arrayWithObjects:@"aaa",@"bbb", nil];
  788. //
  789. // __weak typeof(self) weakSelf = self;
  790. // dispatch_async(dispatch_get_global_queue(0, 0), ^{
  791. // NSDictionary *contentDic = [RANetwork query:dic];
  792. // NSInteger result = [[contentDic objectForKey:@"result"] integerValue];
  793. // dispatch_async(dispatch_get_main_queue(), ^{
  794. // if (weakSelf) {
  795. // __strong typeof(weakSelf) strongSelf = weakSelf;
  796. // if (result == RESULT_TRUE) {
  797. // strongSelf.content_layout = [contentDic objectForKey:@"layout"];
  798. // strongSelf.content_action = [contentDic objectForKey:@"row_action"];
  799. // strongSelf.content_menu = [[contentDic objectForKey:@"menu"] mutableCopy];
  800. // [strongSelf setupNavigationBar];
  801. //
  802. // UILabel * headerview=(UILabel *)self.tableview.tableHeaderView;
  803. // headerview.text = contentDic[@"table_title"];
  804. // [self resize_tableHeader];
  805. //
  806. // if(strongSelf.content_data==nil)
  807. // strongSelf.content_data = [NSMutableDictionary new];
  808. // NSMutableDictionary* newdata = [[contentDic objectForKey:@"data"] mutableCopy];
  809. // for(int dc = 0;dc<[newdata[@"count"] intValue];dc++)
  810. // {
  811. // NSMutableDictionary * newdata_item = newdata[[NSString stringWithFormat:@"item_%d",dc]];
  812. //
  813. // strongSelf.content_data[[NSString stringWithFormat:@"item_%d",[strongSelf.content_data[@"count"] intValue] ]] = newdata_item;
  814. // strongSelf.content_data[@"count"] = @([strongSelf.content_data[@"count"] intValue]+1);
  815. // }
  816. //
  817. //// strongSelf.content_data = [contentDic objectForKey:@"data"];
  818. // [strongSelf updateTableFrame];
  819. // [strongSelf.tableview reloadData];
  820. // } else {
  821. // [RAUtils message_alert:[contentDic objectForKey:@"err_msg"] title:@"Warning" controller:strongSelf];
  822. // }
  823. //
  824. // if (finish) {
  825. // finish((int)result,(int)[self resultItemCount]);
  826. // }
  827. //
  828. // }
  829. //
  830. // });
  831. // });
  832. // }
  833. }
  834. - (void)updateTableFrame {
  835. // auto resizing
  836. // int width=[self.content_layout[@"header"][@"width"] intValue];
  837. // if(width<self.tableview.frame.size.width)
  838. // width=self.tableview.frame.size.width;
  839. //
  840. // CGRect frame = CGRectMake(self.tableview.frame.origin.x, self.tableview.frame.origin.y, width, self.tableview.frame.size.height);
  841. // self.tableview.frame=frame;
  842. // self.scrollview.contentSize=self.tableview.frame.size;
  843. // auto layout
  844. int width=[self.content_layout[@"header"][@"width"] intValue];
  845. if(width<self.view.frame.size.width)
  846. width=self.view.frame.size.width;
  847. self.w_constraint.constant = width - CGRectGetWidth(self.view.bounds);
  848. self.h_constraint.constant = 0;
  849. // 约束修改后立即重新布局
  850. [self.view layoutIfNeeded];
  851. if (@available(iOS 11.0,*)) {
  852. UIEdgeInsets edgeInsets = [self.view safeAreaInsets];
  853. CGFloat left = edgeInsets.left;
  854. CGFloat right = edgeInsets.right;
  855. self.lead_constraint.constant = left;
  856. self.trail_constraint.constant = right;
  857. /*
  858. * lead 和 trail改变之前
  859. * scrollview.size.width = self.view.size.width;
  860. * 改变后
  861. * scrollview.size.width = self.view.size.width - left - right;
  862. * 由于w_contraint本质上是根据scrolliew.size.width决定,实际上使用self.view.size.width计算得到
  863. * 所以w_contraint需要 +left +right补偿偏差。
  864. */
  865. self.w_constraint.constant += left + right;
  866. // 约束修改后立即重新布局
  867. [self.view layoutIfNeeded];
  868. }
  869. }
  870. #pragma mark - RefreshDelegate
  871. - (void)jl_pullRefresh:(JLRefreshBasis *)refresh state:(JLRefreshState)state percentage:(float)percentage {
  872. // NSString *title = [refresh refreshTitleForState:state];
  873. // CGFloat offset = refresh.jl_height * percentage;
  874. if ([refresh isEqual:self.tableview.jl_header]) {
  875. // self.refreshHeaderTitleLb.text = title;
  876. // self.header_top_constraint.constant = offset;
  877. }
  878. if (refresh == self.tableview.jl_footer) {
  879. // self.refreshFooterTitleLb.text = title;
  880. // self.footer_top_constraint.constant = -offset;
  881. }
  882. }
  883. - (void)jl_endRefresh:(JLRefreshBasis *)refresh {
  884. // state == idle
  885. // refresh UI
  886. [self.tableview reloadData];
  887. if (refresh == self.tableview.jl_footer && refresh.state == JLRefreshStateNoMore) {
  888. }
  889. }
  890. - (void)jl_beginRefresh:(JLRefreshBasis *)refresh {
  891. // state == refreshing
  892. // load data
  893. // finish loading data
  894. int option = 0;
  895. if ([refresh isEqual:self.tableview.jl_header]) {
  896. option = 1;
  897. }
  898. if (refresh == self.tableview.jl_footer) {
  899. if(refresh.state==JLRefreshStateNoMore) //数据取完不再加载
  900. return;
  901. option = 2;
  902. }
  903. self.tableview.userInteractionEnabled = NO;
  904. __weak typeof(self) weakSelf = self;
  905. [self loadContentWithOption:option Complete:^(int result, int count) {
  906. weakSelf.tableview.userInteractionEnabled = YES;
  907. if ([refresh isEqual:weakSelf.tableview.jl_header]) {
  908. [weakSelf.tableview.jl_header performSelector:@selector(endRefresh)];
  909. }
  910. if (refresh == weakSelf.tableview.jl_footer) {
  911. [weakSelf.tableview.jl_footer performSelector:@selector(endRefresh)];
  912. if (result == 2 && count < delta) {
  913. [weakSelf.tableview.jl_footer performSelector:@selector(noMoreData)];
  914. }
  915. }
  916. }];
  917. }
  918. #pragma mark - Quick Look
  919. - (MyQLPreviewController *)quickLook {
  920. if (!_quickLook)
  921. {
  922. _quickLook = [[MyQLPreviewController alloc] init];
  923. _quickLook.delegate = self;
  924. _quickLook.dataSource = self;
  925. }
  926. else
  927. {
  928. [_quickLook reloadData];
  929. }
  930. return _quickLook;
  931. }
  932. #pragma mark - QuickLook Data Source
  933. - (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller {
  934. return 1;
  935. }
  936. - (id <QLPreviewItem>) previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index {
  937. if(self.documentPath==nil)
  938. return nil;
  939. return [NSURL fileURLWithPath:self.documentPath];
  940. }
  941. #pragma mark - QuickLook Delegate
  942. - (void) previewControllerDidDismiss:(QLPreviewController *)controller {
  943. }
  944. /**
  945. * 文件内部链接点击不进行外部跳转
  946. */
  947. - (BOOL) previewController:(QLPreviewController *)controller shouldOpenURL:(NSURL *)url forPreviewItem:(id<QLPreviewItem>)item {
  948. return NO;
  949. }
  950. #pragma mark - customize editor
  951. - (UIView*)get_tableHeader
  952. {
  953. UILabel * headerview = [UILabel new];
  954. headerview.frame = CGRectMake(0, 0, self.tableview.frame.size.width, 44);
  955. headerview.numberOfLines = 0;
  956. headerview.textAlignment = NSTextAlignmentCenter;
  957. headerview.text = @"";
  958. return headerview;
  959. }
  960. -(void) resize_tableHeader
  961. {
  962. //利用systemLayoutSizeFittingSize:计算出真实高度
  963. CGFloat height = [self.tableview.tableHeaderView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
  964. CGRect headerFrame = self.tableview.tableHeaderView.frame;
  965. headerFrame.size.height = height+20;//20是留的上下边距
  966. //修改tableHeaderView的frame
  967. self.tableview.tableHeaderView.frame = headerFrame;
  968. }
  969. #pragma mark - 3D Touch Delegate (PreviewingDelegate)
  970. // peek (预览)
  971. - (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location {
  972. // [previewingContext sourceView]即为所按压的视图
  973. // UITableViewCell *view = (UITableViewCell *)[previewingContext sourceView];
  974. //
  975. // // 设置不被虚化的范围
  976. // CGRect rect = view.bounds;
  977. // [previewingContext setSourceRect:rect];
  978. //
  979. // NSIndexPath *indexPath = [self.tableview indexPathForCell:view];
  980. // // peek (预览界面)
  981. // UIViewController *tvc = [self viewControllerFor3DTouch:indexPath];
  982. //
  983. // tvc.preferredContentSize = CGSizeMake(0, 480); // 预览图的大小
  984. //
  985. // return tvc;
  986. // NSIndexPath *indexPath = [self.tableview indexPathForCell:view];
  987. // [self presses3DTouchForIndexPath:indexPath];
  988. return nil;
  989. }
  990. // pop (在预览基础上更用力按压)
  991. - (void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit {
  992. // [self showViewController:viewControllerToCommit sender:self];
  993. }
  994. #pragma mark - Cell Touch Delegate
  995. - (void)touchedCell:(ResultCell *)cell withForce:(float)force {
  996. if (force > 4.0f) {
  997. cell.handlingTouch = YES;
  998. // 1519: 普通短震,3D Touch 中 Peek 震动反馈
  999. // 1520: 普通短震,3D Touch 中 Pop 震动反馈
  1000. // 1521: 连续三次短震
  1001. // kSystemSoundID_Vibrate: 震动很暴力,不适合震动反馈
  1002. AudioServicesPlaySystemSound(1519); // 支持震动的设备上会震动,不支持就什么都不做 kSystemSoundID_Vibrate
  1003. NSIndexPath *indexPath = [self.tableview indexPathForCell:cell];
  1004. [self presses3DTouchForIndexPath:indexPath];
  1005. }
  1006. NSLog(@"force %f",force);
  1007. }
  1008. @end