selectTreeVC.m 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. //
  2. // selectTreeVC.h.m
  3. //
  4. // Created by flyeagleTang on 14-4-3.
  5. // Copyright (c) 2014年 Reese. All rights reserved.
  6. //
  7. #import "selectTreeVC.h"
  8. #import "JXChatViewController.h"
  9. #import "AppDelegate.h"
  10. #import "JXLabel.h"
  11. #import "JXImageView.h"
  12. //#import "JXCell.h"
  13. #import "JXRoomPool.h"
  14. #import "JXTableView.h"
  15. #import "JXNewFriendViewController.h"
  16. #import "menuImageView.h"
  17. #import "JXConstant.h"
  18. #import "selectValueVC.h"
  19. #define row_height 40
  20. @interface selectTreeVC ()
  21. @end
  22. @implementation selectTreeVC
  23. @synthesize parentId,parentName;
  24. @synthesize selected;
  25. @synthesize delegate;
  26. @synthesize didSelect;
  27. @synthesize selValue;
  28. @synthesize selNumber;
  29. - (id)init
  30. {
  31. self = [super init];
  32. if (self) {
  33. self.heightHeader = JX_SCREEN_TOP;
  34. self.heightFooter = 0;
  35. self.isGotoBack = YES;
  36. //self.view.frame = CGRectMake(0, 0, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT);
  37. [self createHeadAndFoot];
  38. self.isShowFooterPull = NO;
  39. self.isShowHeaderPull = NO;
  40. _table.backgroundColor = [UIColor whiteColor];
  41. _ids = [[NSMutableArray alloc]init];
  42. _names = [[NSMutableArray alloc]init];
  43. _selIds = [[NSMutableArray alloc]init];
  44. _selNames = [[NSMutableArray alloc]init];
  45. _typeIds = [[NSMutableArray alloc]init];
  46. _typeNames = [[NSMutableArray alloc]init];
  47. [g_constant getNameValues:parentId name:_typeNames value:_typeIds];
  48. for(int i=0;i<[_typeIds count];i++){
  49. NSMutableArray* p1 = [[NSMutableArray alloc]init];
  50. NSMutableArray* p2 = [[NSMutableArray alloc]init];
  51. int n = [[_typeIds objectAtIndex:i] intValue];
  52. // NSLog(@"%d",n);
  53. [g_constant getNameValues:n name:p1 value:p2];
  54. [_names addObject:p1];
  55. [_ids addObject:p2];
  56. // [p1 release];
  57. // [p2 release];
  58. }
  59. }
  60. return self;
  61. }
  62. - (void)dealloc {
  63. [_ids removeAllObjects];
  64. [_names removeAllObjects];
  65. [_typeIds removeAllObjects];
  66. [_typeNames removeAllObjects];
  67. [_selIds removeAllObjects];
  68. [_selNames removeAllObjects];
  69. self.parentName = nil;
  70. self.selValue = nil;
  71. self.selNames = nil;
  72. self.selIds = nil;
  73. // [_ids release];
  74. // [_names release];
  75. // [_typeIds release];
  76. // [_typeNames release];
  77. // [super dealloc];
  78. }
  79. - (void)viewDidLoad
  80. {
  81. [super viewDidLoad];
  82. }
  83. - (void)viewWillAppear:(BOOL)animated
  84. {
  85. [super viewWillAppear:animated];
  86. }
  87. - (void)didReceiveMemoryWarning
  88. {
  89. [super didReceiveMemoryWarning];
  90. // Dispose of any resources that can be recreated.
  91. }
  92. #pragma mark ---------tableView协议----------------
  93. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  94. {
  95. return [_typeNames count];
  96. }
  97. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  98. {
  99. NSArray* p = [_names objectAtIndex:section];
  100. return [p count];
  101. }
  102. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
  103. UIView* v = [[UIView alloc]initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, row_height)];
  104. v.backgroundColor = [UIColor grayColor];
  105. v.backgroundColor = [UIColor colorWithRed:0.85 green:0.85 blue:0.85 alpha:1];
  106. UILabel* p = [[UILabel alloc]initWithFrame:CGRectMake(20, 0, 300, row_height)];
  107. p.text = [_typeNames objectAtIndex:section];
  108. p.font = g_factory.font15;
  109. p.textColor = [UIColor grayColor];
  110. [v addSubview:p];
  111. // [p release];
  112. UIView* line = [[UIView alloc]initWithFrame:CGRectMake(0,row_height-LINE_WH,JX_SCREEN_WIDTH,LINE_WH)];
  113. line.backgroundColor = THE_LINE_COLOR;
  114. [v addSubview:line];
  115. // [line release];
  116. [_table addToPool:v];
  117. return v;
  118. }
  119. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  120. {
  121. UITableViewCell *cell=nil;
  122. NSString* cellName = [NSString stringWithFormat:@"msg_%d_%ld_%ld",_refreshCount,indexPath.row,indexPath.section];
  123. cell = [tableView dequeueReusableCellWithIdentifier:cellName];
  124. if(cell==nil){
  125. cell = [UITableViewCell alloc];
  126. [_table addToPool:cell];
  127. cell = [cell initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
  128. UILabel* p = [[UILabel alloc]initWithFrame:CGRectMake(20, 0, 300, row_height)];
  129. p.font = g_factory.font15;
  130. [cell addSubview:p];
  131. // [p release];
  132. NSArray* a = [_names objectAtIndex:indexPath.section];
  133. p.text = [a objectAtIndex:indexPath.row];
  134. a = nil;
  135. UIView* line = [[UIView alloc] initWithFrame:CGRectMake(18,row_height-LINE_WH,300,LINE_WH)];
  136. line.backgroundColor = THE_LINE_COLOR;
  137. [cell addSubview:line];
  138. // [line release];
  139. UIImageView* iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"more_flag"]];
  140. iv.frame = CGRectMake(JX_SCREEN_WIDTH-20, (row_height-13)/2, 7, 13);
  141. [cell addSubview:iv];
  142. // [iv release];
  143. }
  144. return cell;
  145. }
  146. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  147. { [super tableView:tableView didSelectRowAtIndexPath:indexPath];
  148. if(self.hasSubtree){
  149. [_selNames removeAllObjects];
  150. [_selIds removeAllObjects];
  151. int n = [[[_ids objectAtIndex:indexPath.section] objectAtIndex:indexPath.row] intValue];
  152. [g_constant getNameValues:n name:_selNames value:_selIds];
  153. selectValueVC* vc = [selectValueVC alloc];
  154. vc.values = _selNames;
  155. vc.selNumber = selNumber;
  156. vc.numbers = _selIds;
  157. vc.didSelect = @selector(doSelect:);
  158. vc.delegate = self;
  159. vc.quickSelect = YES;
  160. vc = [vc init];
  161. // [g_window addSubview:vc.view];
  162. [g_navigation pushViewController:vc animated:YES];
  163. }else{
  164. self.selected = (int)indexPath.row;
  165. NSArray* a = [_names objectAtIndex:indexPath.section];
  166. self.selValue = [a objectAtIndex:indexPath.row];
  167. a = [_ids objectAtIndex:indexPath.section];
  168. self.selNumber = [[a objectAtIndex:indexPath.row] intValue];
  169. // NSLog(@"选中%@,%d",self.selValue,self.selected);
  170. if (delegate && [delegate respondsToSelector:didSelect])
  171. // [delegate performSelector:didSelect withObject:self];
  172. [delegate performSelectorOnMainThread:didSelect withObject:self waitUntilDone:NO];
  173. [self actionQuit];
  174. }
  175. return;
  176. }
  177. -(void)doSelect:(selectValueVC*)sender{
  178. self.selValue = sender.selValue;
  179. self.selected = sender.selected;
  180. self.selNumber = sender.selNumber;
  181. // NSLog(@"选中%@,%d,%d",self.selValue,self.selected,selNumber);
  182. if (delegate && [delegate respondsToSelector:didSelect])
  183. // [delegate performSelector:didSelect withObject:self];
  184. [delegate performSelectorOnMainThread:didSelect withObject:self waitUntilDone:NO];
  185. [self actionQuit];
  186. }
  187. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  188. {
  189. return row_height;
  190. }
  191. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  192. return row_height;
  193. }
  194. @end