BundleModelViewController.m 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. //
  2. // BundleModelViewController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 10/31/15.
  6. // Copyright © 2015 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "BundleModelViewController.h"
  9. #import "const.h"
  10. #import "BundleModelCell.h"
  11. #define DEF_CELL_HEIGHT 44
  12. //#define DEF_TABLE_HEIGHT 44
  13. //#define LINE_WIDTH 0
  14. //#define CELL_MARGIN 0
  15. #define LABEL_MARGIN 11
  16. @interface BundleModelViewController ()
  17. @end
  18. @implementation BundleModelViewController
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. self.navigationItem.title=@"Bundle Items";
  22. UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"close"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
  23. style:UIBarButtonItemStylePlain
  24. target:self
  25. action:@selector( onCloseClick:)];
  26. //[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Close", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onCloseClick:)];
  27. // closeButton.title = @"Close";
  28. self.navigationItem.rightBarButtonItem = closeButton;
  29. // Do any additional setup after loading the view.
  30. }
  31. - (void)onCloseClick:(UIButton *)sender {
  32. [self dismissViewControllerAnimated:true completion:nil];
  33. }
  34. - (void)didReceiveMemoryWarning {
  35. [super didReceiveMemoryWarning];
  36. // Dispose of any resources that can be recreated.
  37. }
  38. /*
  39. #pragma mark - Navigation
  40. // In a storyboard-based application, you will often want to do a little preparation before navigation
  41. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  42. // Get the new view controller using [segue destinationViewController].
  43. // Pass the selected object to the new view controller.
  44. }
  45. */
  46. #pragma mark - Table view data source
  47. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  48. {
  49. NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  50. NSString* value = [item_json valueForKey:@"description"];
  51. float width = 254;
  52. width-=40;
  53. CGSize constraintkey = CGSizeMake(width-2*LABEL_MARGIN, 10.0f);//key label width is 40% cell width;
  54. CGRect frame;
  55. frame.size = constraintkey;
  56. frame.origin.x=0;
  57. frame.origin.y=0;
  58. RTLabel* rtlabel = [[RTLabel alloc] initWithFrame:frame];
  59. [rtlabel setText: value];
  60. CGSize optimumSize = [rtlabel optimumSize];
  61. float height = optimumSize.height;
  62. height = MAX(height+2*LABEL_MARGIN, DEF_CELL_HEIGHT);
  63. return height;
  64. }
  65. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  66. //{
  67. // return 0;
  68. //}
  69. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  70. //{
  71. // return 0;
  72. //}
  73. //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  74. //{
  75. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  76. // return myView;
  77. //
  78. //}
  79. //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  80. //{
  81. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  82. //// myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  83. //// UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 90, 22)];
  84. //// titleLabel.textColor=[UIColor whiteColor];
  85. //// titleLabel.backgroundColor = [UIColor clearColor];
  86. //// if(section==0)
  87. //// titleLabel.text=NSLocalizedString(@"display_items", nil);
  88. //// else
  89. //// titleLabel.text=NSLocalizedString(@"hide_items", nil);
  90. //// [titleLabel sizeToFit];
  91. //// [myView addSubview:titleLabel];
  92. ////
  93. // return myView;
  94. //}
  95. //
  96. //- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  97. // if(section==0)
  98. // return nil;
  99. // else
  100. // return @"detail section";
  101. //}
  102. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  103. {
  104. return 1;
  105. }
  106. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  107. {
  108. return 33;
  109. }
  110. - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  111. {
  112. UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  113. myView.backgroundColor = UIColorFromRGB(0x996633);
  114. myView.layer.shadowColor = [UIColor blackColor].CGColor;
  115. myView.layer.shadowOffset = CGSizeMake(0, 0);
  116. myView.layer.shadowOpacity = 0.5;
  117. myView.layer.shadowRadius = 2.0;
  118. UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(50, 5.5, 90, 22)];
  119. modellabel.textColor=[UIColor whiteColor];
  120. modellabel.backgroundColor = [UIColor clearColor];
  121. modellabel.text=NSLocalizedString(@"Model", nil);
  122. [modellabel sizeToFit];
  123. [myView addSubview:modellabel];
  124. UILabel *description = [[UILabel alloc] initWithFrame:CGRectMake(200, 5.5, 90, 22)];
  125. description.textColor=[UIColor whiteColor];
  126. description.backgroundColor = [UIColor clearColor];
  127. description.text=NSLocalizedString(@"Description", nil);
  128. [description sizeToFit];
  129. [myView addSubview:description];
  130. UILabel *qtylabel = [[UILabel alloc] initWithFrame:CGRectMake(400, 5.5, 90, 22)];
  131. qtylabel.textColor=[UIColor whiteColor];
  132. qtylabel.backgroundColor = [UIColor clearColor];
  133. qtylabel.text=NSLocalizedString(@"QTY", nil);
  134. [qtylabel sizeToFit];
  135. [myView addSubview:qtylabel];
  136. UILabel *pricelabel = [[UILabel alloc] initWithFrame:CGRectMake(450, 5.5, 90, 22)];
  137. pricelabel.textColor=[UIColor whiteColor];
  138. pricelabel.backgroundColor = [UIColor clearColor];
  139. pricelabel.text=NSLocalizedString(@"Unit Price", nil);
  140. [pricelabel sizeToFit];
  141. [myView addSubview:pricelabel];
  142. //
  143. return myView;
  144. }
  145. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  146. {
  147. // NSDictionary * item_json = [self.content_data objectForKey:@"items"];
  148. int count =[[self.content_data valueForKey:@"count"] intValue];
  149. return count;
  150. }
  151. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  152. {
  153. // if(tableView==self.itemListTable)
  154. // {
  155. NSString *CellIdentifier = @"BundleModelCell";
  156. BundleModelCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  157. NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  158. cell.labelModel.text = [item_json valueForKey:@"model"];
  159. cell.labelPrice.text=[NSString stringWithFormat:@"$ %.2f",[[item_json valueForKey:@"unit_price"] floatValue]];
  160. cell.labelQTY.text=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"modulus"] intValue]];
  161. cell.labelDescription.text = [item_json valueForKey:@"description"];
  162. cell.backgroundColor = [UIColor whiteColor];
  163. return cell;
  164. // }
  165. // else
  166. // {
  167. // NSString *CellIdentifier = @"OrderInfoListItem";
  168. // UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  169. // return cell;
  170. // }
  171. }
  172. @end