DetailPageViewController.m 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. //
  2. // DetailPageViewController.m
  3. // Apex Mobile
  4. //
  5. // Created by Ray on 14-3-8.
  6. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "DetailPageViewController.h"
  9. #define DEF_CELL_HEIGHT 44
  10. #define DEF_TABLE_HEIGHT 44
  11. #define LINE_WIDTH 0
  12. #define CELL_MARGIN 0
  13. #define LABEL_MARGIN 5
  14. #import "TabBarController.h"
  15. @interface DetailPageViewController ()
  16. @end
  17. @implementation DetailPageViewController
  18. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  19. {
  20. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  21. if (self) {
  22. // Custom initialization
  23. }
  24. return self;
  25. }
  26. -(void)changeCell
  27. {
  28. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  29. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"refreshing"];
  30. [self performSelector:@selector(ReloadData) withObject:nil afterDelay:1];
  31. DebugLog(@"refresh!!!!!!!!");
  32. }
  33. -(void)ReloadData
  34. {
  35. // Count ++ ;
  36. // [mytabelview reloadData];
  37. [self loadpage];
  38. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  39. [reF endRefreshing];
  40. }
  41. - (void)viewDidLoad
  42. {
  43. [super viewDidLoad];
  44. // self.webviewoprationQueue = [[NSOperationQueue alloc] init];
  45. // self.webviewoprationQueue.maxConcurrentOperationCount = 1;
  46. UIRefreshControl *ref = [[UIRefreshControl alloc]init];
  47. ref.tag = 200 ;
  48. ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"drag to refresh"];
  49. ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  50. // ref.hidden = true;
  51. [ref addTarget:self action:@selector(changeCell) forControlEvents:UIControlEventValueChanged];
  52. [self.table addSubview:ref];
  53. if(self.tabBarController.tabBar.hidden==true)
  54. {
  55. CGRect frame = self.table.frame;
  56. frame.size.height +=40;
  57. self.table.frame=frame;
  58. }
  59. // self.view.backgroundColor= [UIColor whiteColor];
  60. [self loadpage];
  61. // Do any additional setup after loading the view.
  62. }
  63. - (void)didReceiveMemoryWarning
  64. {
  65. [super didReceiveMemoryWarning];
  66. // Dispose of any resources that can be recreated.
  67. }
  68. -(void) loadpage
  69. {
  70. // [self.params setValue:[NSString stringWithFormat:@"%d",self.offset] forKey:@"offset"];
  71. // self.prepageButton.enabled=false;
  72. // self.nextpageButton.enabled=false;
  73. self.mum.center = self.view.center;
  74. NSTimeInterval animationDuration = 0.30f;
  75. [UIView beginAnimations:@"ResizeView" context:nil];
  76. [UIView setAnimationDuration:animationDuration];
  77. self.mum.hidden = false;
  78. self.table.hidden = true;
  79. [UIView commitAnimations];
  80. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  81. self.content=[ApexMobileNetwork get_detailcontent:self.params];
  82. // PageData* pageData=nil;
  83. // if(self.recordCount==-1)
  84. // self.recordCount=[ApexMobileNetwork get_recordcount: self.params ];
  85. // if(self.recordCount>0)
  86. // {
  87. // self.pageData=[ApexMobileNetwork get_pagedata:self.params];
  88. // // self.pageData=[ApexMobileNetwork]
  89. // }
  90. //
  91. dispatch_async(dispatch_get_main_queue(), ^{
  92. NSTimeInterval animationDuration = 0.30f;
  93. [UIView beginAnimations:@"ResizeView" context:nil];
  94. [UIView setAnimationDuration:animationDuration];
  95. self.mum.hidden = true;
  96. if(self.content.result_code!=RESULT_TRUE)
  97. {
  98. self.table.hidden =false;
  99. [self.table reloadData];
  100. }
  101. else
  102. if([self.content get_segmentcount]==0)
  103. {
  104. self.table.hidden =true;
  105. self.norecordLabel.hidden=false;
  106. }
  107. else
  108. {
  109. self.table.hidden =false;
  110. [self.table reloadData];
  111. }
  112. [UIView commitAnimations];
  113. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  114. bool autologin =[defaults boolForKey:@"autologin"];
  115. if(!autologin)
  116. {
  117. TabBarController * viewController =[self.storyboard instantiateViewControllerWithIdentifier:@"LoginTabBar"];
  118. [self presentViewController:viewController animated:YES completion:^{
  119. }];
  120. }
  121. // [self.table setNeedsDisplay];
  122. // if(self.recordCount<2000)
  123. // self.countView.title = [NSString stringWithFormat:@"%d records",self.recordCount];
  124. // else
  125. // self.countView.title = @"2000+ records";
  126. //
  127. // if(self.offset<self.pageData.get_count)
  128. // self.prepageButton.enabled=false;
  129. // else
  130. // self.prepageButton.enabled=true;
  131. // if(self.offset+self.pageData.get_count>=self.recordCount)
  132. // self.nextpageButton.enabled=false;
  133. // else
  134. // self.nextpageButton.enabled=true;
  135. // [self.grid initgrid :self.pageData];
  136. });
  137. });
  138. }
  139. - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
  140. {
  141. // [self.table beginUpdates];
  142. [self.table reloadData];
  143. // [self.table endUpdates];
  144. }
  145. //// 是否支持屏幕旋转
  146. //- (BOOL)shouldAutorotate {
  147. //
  148. //
  149. // return YES;
  150. //}
  151. //// 支持的旋转方向
  152. //- (NSUInteger)supportedInterfaceOrientations {
  153. // return UIInterfaceOrientationLandscapeRight;//UIInterfaceOrientationMaskAllButUpsideDown;
  154. //}
  155. //// 一开始的屏幕旋转方向
  156. //- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
  157. // return UIInterfaceOrientationLandscapeRight;
  158. //}
  159. #pragma mark - web view delegate
  160. - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
  161. {
  162. if(navigationType != UIWebViewNavigationTypeLinkClicked)
  163. return true;
  164. // NSString *currentURL =[webView.request.URL lastPathComponent];// [webView stringByEvaluatingJavaScriptFromString:@"document.title"];
  165. NSString* str = request.URL.absoluteString;
  166. if([str isEqualToString:@"about:blank"])
  167. return true;
  168. WebViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"WebViewController"];
  169. ViewController.url = str;
  170. // ViewController. = self.function_name;
  171. // ViewController.behavior =BEHAVIOR_SEARCH;
  172. [self.navigationController pushViewController:ViewController animated:YES];
  173. DebugLog(@"shouldStartLoadWithRequest");
  174. return false;
  175. }
  176. - (void)webViewDidFinishLoad:(UIWebView *)webView
  177. {
  178. DebugLog(@"webViewDidFinishLoad @@@@@@@@@@@@@@@@@ entry");
  179. UITableViewCell *cell = (UITableViewCell *)[[webView superview] superview];
  180. NSIndexPath *indexPath = [self.table indexPathForCell:cell];
  181. if(indexPath==nil)
  182. {//for ios7
  183. cell = (UITableViewCell *) webView.superview.superview.superview;
  184. indexPath = [self.table indexPathForCell:cell];
  185. }
  186. float height= [[self.content.webviewHeight valueForKey:[NSString stringWithFormat:@"%ld",(long)indexPath.section]] floatValue];
  187. if(height>0)
  188. return;
  189. // UIScrollView *scrollerView = [webView.subviews objectAtIndex:0];
  190. // CGSize size= webView.scrollView.contentSize;
  191. // CGSize fittingSize = [webView sizeThatFits:CGSizeZero];
  192. CGRect frame = webView.frame;
  193. NSString *fitHeight = [webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight;"];
  194. frame.size.height = [fitHeight floatValue];
  195. //webView.frame = frame;
  196. // DebugLog(@"webViewDidFinishLoad ^^^^^^^^^^^^^^^^^Saveheight height=%f section=%ld",webView.scrollView.contentSize.height,indexPath.section);
  197. [self.content.webviewHeight setObject:[NSString stringWithFormat:@"%f",frame.size.height/*webView.scrollView.contentSize.height*/] forKey:[NSString stringWithFormat:@"%ld",(long)indexPath.section]];
  198. DebugLog(@"webViewDidFinishLoad ^^^^^^^^^^^^^^^^^reloadRowsAtIndexPaths");
  199. // [self.table beginUpdates];
  200. [self.table reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
  201. // [self.table endUpdates];
  202. // [self.webviewoprationQueue addOperationWithBlock:^{
  203. // }];
  204. // [self.table endUpdates];
  205. // }
  206. }
  207. #pragma mark - Table view data source
  208. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  209. //{
  210. // return 40;
  211. //}
  212. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  213. {
  214. DebugLog(@"heightForRowAtIndexPath");
  215. // float height = [self.content itemHeightAtIndexPath:indexPath];
  216. NSString* type = [self.content get_segmenttype:indexPath.section];
  217. if([type isEqualToString:@"table"])
  218. {
  219. // [self.content.webviewHeight setObject:[NSString stringWithFormat:@"%f",webView.frame.size.height] forKey:[NSString stringWithFormat:@"%d",webView.tag]];
  220. float height= [[self.content.webviewHeight valueForKey:[NSString stringWithFormat:@"%ld",(long)indexPath.section]] floatValue];
  221. if(height==0)
  222. height=DEF_TABLE_HEIGHT;
  223. // DebugLog(@"heightForRowAtIndexPath...............webview,hight = %f section=%ld",height,indexPath.section);
  224. //wait(1000);
  225. return height;
  226. }
  227. else if([type isEqualToString:@"mapping"])
  228. {
  229. float width = tableView.frame.size.width;
  230. width-=CELL_MARGIN*2;
  231. CGSize constraintkey = CGSizeMake(width*0.4-2*LABEL_MARGIN, 20000.0f);//key label width is 40% cell width;
  232. CGSize constraintval = CGSizeMake(width*0.6-2*LABEL_MARGIN, 20000.0f);//val label width is 60% cell width;
  233. NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
  234. NSString* key =[item allKeys][0];
  235. // [cell.keyLabel sizeToFit];
  236. NSString* val=[item valueForKey:key];
  237. if([val isEqual:[NSNull null]])
  238. val=@"";
  239. if(val==nil)
  240. val=@"";
  241. if([val isEqualToString:@"null"])
  242. val=@"";
  243. CGRect frame;
  244. frame.size = constraintval;
  245. frame.origin.x=0;
  246. frame.origin.y=0;
  247. RTLabel* rtlabel = [[RTLabel alloc] initWithFrame:frame];
  248. [rtlabel setLineBreakMode: RTTextLineBreakModeWordWrapping];
  249. // rtlabel.lineSpacing = 20.0;
  250. [rtlabel setText: val];
  251. CGSize sizeval=rtlabel.optimumSize;
  252. CGSize sizekey = [key sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  253. // CGSize sizeval = [val sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintval lineBreakMode:NSLineBreakByWordWrapping];
  254. float height = MAX(sizekey.height,sizeval.height);
  255. height = MAX(height+LINE_WIDTH, DEF_CELL_HEIGHT);
  256. /*
  257. NSString *text = [items objectAtIndex:[indexPath row]];
  258. CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 20000.0f);
  259. CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
  260. CGFloat height = MAX(size.height, 44.0f);
  261. return height + (CELL_CONTENT_MARGIN * 2);
  262. */
  263. // NSString *CellIdentifier = @"detail_item_kv";
  264. // DetailCellKV *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  265. // NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
  266. // cell.keyLabel.text=[item allKeys][0];
  267. // [cell.keyLabel sizeToFit];
  268. // cell.valLabel.text= [item valueForKey:cell.keyLabel.text];
  269. // [cell.valLabel sizeToFit];
  270. //
  271. // return MAX(cell.keyLabel.frame.size.height,cell.valLabel.frame.size.height);
  272. return height;
  273. }
  274. else
  275. {
  276. DebugLog(@"cellForRowAtIndexPath =====> list");
  277. float width = tableView.frame.size.width;
  278. width-=CELL_MARGIN*2;
  279. CGSize constraintval = CGSizeMake(width, 20000.0f);//val label width is 60% cell width;
  280. NSDictionary* item = self.content.segments[indexPath.section];
  281. NSString* text=[item valueForKey:[NSString stringWithFormat:@"line%ld",(long)indexPath.row]];
  282. if([text isEqual:[NSNull null]])
  283. text=@"";
  284. if(text==nil)
  285. text=@"";
  286. if([text isEqualToString:@"null"])
  287. text=@"";
  288. // CGRect frame;
  289. // frame.size = constraintval;
  290. // frame.origin.x=0;
  291. // frame.origin.y=0;
  292. CGSize sizeText = [text sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintval lineBreakMode:NSLineBreakByWordWrapping];
  293. // CGSize sizeval = [val sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintval lineBreakMode:NSLineBreakByWordWrapping];
  294. float height = sizeText.height;
  295. height = MAX(height+LINE_WIDTH, DEF_CELL_HEIGHT);
  296. return height;
  297. }
  298. // return height;
  299. }
  300. - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  301. {
  302. UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)];
  303. myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  304. UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 90, 22)];
  305. titleLabel.textColor=[UIColor whiteColor];
  306. titleLabel.backgroundColor = [UIColor clearColor];
  307. titleLabel.text =[self.content get_segmentname:section];
  308. [titleLabel sizeToFit];
  309. [myView addSubview:titleLabel];
  310. return myView;
  311. }
  312. //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  313. //{
  314. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)];
  315. // myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  316. //// UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 90, 22)];
  317. //// titleLabel.textColor=[UIColor whiteColor];
  318. //// titleLabel.backgroundColor = [UIColor grayColor];
  319. //// titleLabel.text =[self.content get_segmentname:section];
  320. //// [titleLabel sizeToFit];
  321. //// [myView addSubview:titleLabel];
  322. //
  323. // return myView;
  324. //}
  325. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  326. {
  327. DebugLog(@"numberOfSectionsInTableView=%ld",[self.content get_segmentcount]);
  328. return [self.content get_segmentcount];
  329. }
  330. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  331. {
  332. DebugLog(@"numberOfRowsInSection=%d",[self.content get_itemcount:section]);
  333. return [self.content get_itemcount:section];
  334. }
  335. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  336. DebugLog(@"titleForHeaderInSection=%@",[self.content get_segmentname:section]);
  337. return [self.content get_segmentname:section];
  338. }
  339. //- (UIImage *) imageWithTintColor:(UIImage*)source Color:(UIColor *)tintColor blendMode:(CGBlendMode)blendMode {
  340. // //We want to keep alpha, set opaque to NO; Use 0.0f for scale to use the scale factor of the device’s main screen.
  341. // UIGraphicsBeginImageContextWithOptions(source.size, NO, 0.0f); [tintColor setFill];
  342. // CGRect bounds = CGRectMake(0, 0, source.size.width, source.size.height); UIRectFill(bounds);
  343. // //Draw the tinted image in context
  344. // [source drawInRect:bounds blendMode:blendMode alpha:1.0f];
  345. // if (blendMode != kCGBlendModeDestinationIn)
  346. // {
  347. // [source drawInRect:bounds blendMode:kCGBlendModeDestinationIn alpha:1.0f];
  348. // }
  349. // UIImage *tintedImage = UIGraphicsGetImageFromCurrentImageContext();
  350. // UIGraphicsEndImageContext();
  351. // return tintedImage;
  352. //}
  353. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  354. {
  355. // NSString *CellIdentifier = @"testcell";
  356. // return [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  357. NSString* type = [self.content get_segmenttype:indexPath.section];
  358. if([type isEqualToString:@"table"])
  359. {
  360. DebugLog(@"cellForRowAtIndexPath =====> table");
  361. static NSString *CellIdentifier = @"detail_item_web";
  362. DetailCellWeb *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  363. NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
  364. NSString* tablecontent = [item valueForKey:@"content"];
  365. cell.webView.tag = indexPath.section;
  366. // cell.webView.scrollView.contentSize.height = 0;
  367. cell.webView.scrollView.bounces=NO;
  368. cell.webView.scrollView.directionalLockEnabled = true;
  369. CGSize size= cell.webView.scrollView.contentSize;
  370. size.height=10;
  371. cell.webView.scrollView.contentSize=size;
  372. // nsstring* c = [NSString stringwith]
  373. // NSString *filePath = [[NSBundle mainBundle]pathForResource:@"about" ofType:@"htm"];
  374. // NSString *htmlString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
  375. [cell.webView loadHTMLString:tablecontent baseURL:nil];
  376. // dispatch_async(dispatch_get_main_queue(), ^{
  377. //
  378. // wait(5000);
  379. // DebugLog(@"!!!!!!!!!!!!!!!!!!!!!!!!!!!webview section=%ld height=%f",indexPath.section,cell.webView.scrollView.contentSize.height);
  380. //
  381. //// DebugLog(@"url:%@", [self.webView stringByEvaluatingJavaScriptFromString:@"window.location.href;"]); // shows google.com instead of about:blank
  382. // });
  383. // CGRect rect = cell.webView.frame;
  384. // [self.content set_itemheight:cell.webView.frame.size.height AtIndexPath:indexPath];
  385. // [cell.webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:filePath]];
  386. return cell;
  387. }
  388. else if([type isEqualToString:@"mapping"])
  389. {
  390. float width = tableView.frame.size.width;
  391. width-=CELL_MARGIN*2;
  392. CGSize constraintkey = CGSizeMake(width*0.4-2*LABEL_MARGIN, 20000.0f);//key label width is 40% cell width;
  393. CGSize constraintval = CGSizeMake(width*0.6-2*LABEL_MARGIN, 20000.0f);//val label width is 60% cell width;
  394. NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
  395. NSString* key =[item allKeys][0];
  396. // [cell.keyLabel sizeToFit];
  397. NSString* val=[item valueForKey:key];
  398. if([val isEqual:[NSNull null]])
  399. val=@"";
  400. if(val==nil)
  401. val=@"";
  402. if([val isEqualToString:@"null"])
  403. val=@"";
  404. CGRect frame;
  405. frame.size = constraintval;
  406. frame.origin.x=0;
  407. frame.origin.y=0;
  408. RTLabel* rtlabel = [[RTLabel alloc] initWithFrame:frame];
  409. [rtlabel setLineBreakMode: RTTextLineBreakModeWordWrapping];
  410. // rtlabel.lineSpacing = 20.0;
  411. [rtlabel setText: val];
  412. CGSize sizeval=rtlabel.optimumSize;
  413. CGSize sizekey = [key sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  414. // CGSize sizeval = [val sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintval lineBreakMode:NSLineBreakByWordWrapping];
  415. // DebugLog(@"tableView width:%f",width);
  416. //
  417. // DebugLog(@"key width= %f val width = %f",constraintkey.width,constraintval.width);
  418. // DebugLog(@"key = %@ val = %@",key,val);
  419. float height = MAX(sizekey.height,sizeval.height);
  420. height = MAX(height, DEF_CELL_HEIGHT-LINE_WIDTH);
  421. sizekey.height = height;
  422. sizekey.width = constraintkey.width;
  423. // sizeval.height = height;
  424. sizeval.width =constraintval.width;
  425. NSString *CellIdentifier = @"detail_item_kv";
  426. DetailCellKV *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  427. if(cell==nil)
  428. DebugLog(@"cell is nil.........................");
  429. // CGRect framekey ;
  430. // framekey.origin.x=CELL_MARGIN;
  431. // framekey.origin.y=LINE_WIDTH;
  432. // framekey.size = sizekey;
  433. // UILabel* keyLabel = [[UILabel alloc]initWithFrame:framekey];
  434. // keyLabel.lineBreakMode = NSLineBreakByWordWrapping;
  435. // keyLabel.backgroundColor = [UIColor grayColor];
  436. // keyLabel.text = key;
  437. //
  438. // CGRect frameval;
  439. // frameval.origin.x=constraintkey.width+CELL_MARGIN;
  440. // frameval.origin.y=LINE_WIDTH;
  441. // frameval.size = sizeval;
  442. //
  443. // UILabel* valLabel = [[UILabel alloc]initWithFrame:frameval];
  444. // valLabel.lineBreakMode = NSLineBreakByWordWrapping;
  445. // valLabel.text = val;
  446. //
  447. // for(UIView* v in cell.contentView.subviews)
  448. // {
  449. // [v removeFromSuperview];
  450. //
  451. // }
  452. //
  453. // [cell.contentView addSubview:keyLabel];
  454. // [cell.contentView addSubview:valLabel];
  455. CGRect framekey = cell.keyLabel.frame;
  456. framekey.origin.x=CELL_MARGIN+LABEL_MARGIN;
  457. framekey.origin.y=LINE_WIDTH;
  458. framekey.size = sizekey;
  459. cell.keyLabel.frame = framekey;
  460. cell.keyLabel.text=key;
  461. CGRect frameval = cell.valLabel.frame;
  462. frameval.origin.x=constraintkey.width+CELL_MARGIN+3*LABEL_MARGIN; //2 margin for key 1 margin for value self
  463. frameval.origin.y=LINE_WIDTH;
  464. frameval.size = sizeval;
  465. cell.valLabel.frame = frameval;
  466. // [cell.valLabel setTextAlignment:RTTextAlignmentCenter];
  467. cell.valLabel.text= val;
  468. CGPoint rcenter;
  469. rcenter.x = width * 0.4+width * 0.6/2;
  470. rcenter.y = height /2;
  471. cell.valLabel.center=rcenter;
  472. // cell.valLabel.backgroundColor =[UIColor redColor];
  473. // cell.contentView.superview.backgroundColor = [UIColor clearColor];
  474. // cell.backgroundColor = [UIColor whiteColor];
  475. UIView * lineview = [[LineView alloc] initWithFrame:cell.contentView.frame];
  476. lineview.userInteractionEnabled = NO;// 不设为NO会屏蔽cell的点击事件
  477. lineview.backgroundColor = [UIColor clearColor];// 设为透明从而使得cell.backgroundColor有效.
  478. lineview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  479. [cell.contentView addSubview:lineview];// cell.contentView是个readonly属性,所以别想着替换contentView了.
  480. // [cell.valLabel sizeToFit];
  481. // cell.anameLabel.text = [field valueForKey:@"aname"];
  482. // [cell.anameLabel sizeToFit];
  483. // DebugLog(@"cellForRowAtIndexPath%@",[field valueForKey:@"aname"]);
  484. // Configure the cell...
  485. // CGRect rect = cell.frame;
  486. // [self.content set_itemheight:100 AtIndexPath:indexPath];
  487. return cell;
  488. }
  489. else
  490. {
  491. DebugLog(@"cellForRowAtIndexPath =====> list");
  492. static NSString *CellIdentifier = @"detail_item_list";
  493. float width = tableView.frame.size.width;
  494. width-=CELL_MARGIN*2;
  495. CGSize constraintkey = CGSizeMake(width, 20000.0f);//key label width is 40% cell width;
  496. NSDictionary* item = self.content.segments[indexPath.section];
  497. NSString* val=[item valueForKey:[NSString stringWithFormat:@"line%ld",(long)indexPath.row]];
  498. if([val isEqual:[NSNull null]])
  499. val=@"";
  500. if(val==nil)
  501. val=@"";
  502. if([val isEqualToString:@"null"])
  503. val=@"";
  504. CGSize sizeval = [val sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  505. float height = sizeval.height;
  506. height = MAX(height, DEF_CELL_HEIGHT-LINE_WIDTH);
  507. sizeval.height = height;
  508. sizeval.width = constraintkey.width;
  509. //创建cell
  510. DetailCellList *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  511. CGRect framekey = cell.listLabel.frame;
  512. framekey.origin.x=CELL_MARGIN;
  513. framekey.origin.y=LINE_WIDTH;
  514. framekey.size = sizeval;
  515. cell.listLabel.frame = framekey;
  516. cell.listLabel.text= val;
  517. return cell;
  518. }
  519. return nil;
  520. }
  521. @end