selectCityVC.m 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. //
  2. // selectCityVC.h.m
  3. //
  4. // Created by flyeagleTang on 14-4-3.
  5. // Copyright (c) 2014年 Reese. All rights reserved.
  6. //
  7. #import "selectCityVC.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 "selectAreaVC.h"
  19. #define row_height 40
  20. @interface selectCityVC ()
  21. @end
  22. @implementation selectCityVC
  23. @synthesize parentId,parentName,showArea;
  24. @synthesize selected;
  25. @synthesize delegate;
  26. @synthesize didSelect;
  27. @synthesize selValue;
  28. @synthesize areaId;
  29. - (id)init
  30. {
  31. self = [super init];
  32. if (self) {
  33. self.areaId = 0;
  34. self.cityId = 0;
  35. self.heightHeader = JX_SCREEN_TOP;
  36. self.heightFooter = 0;
  37. self.isGotoBack = YES;
  38. self.title = self.parentName;
  39. //self.view.frame = CGRectMake(0, 0, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT);
  40. [self createHeadAndFoot];
  41. self.isShowFooterPull = NO;
  42. self.isShowHeaderPull = NO;
  43. _table.backgroundColor = [UIColor whiteColor];
  44. _array = [g_constant getCity:parentId];
  45. _keys = [_array allKeys];
  46. _keys = [_keys sortedArrayUsingSelector:@selector(compare:)];
  47. // [_keys retain];
  48. }
  49. return self;
  50. }
  51. - (void)dealloc {
  52. self.selValue = nil;
  53. self.parentName = nil;
  54. // [_keys release];
  55. [_array removeAllObjects];
  56. // [_array release];
  57. // [super dealloc];
  58. }
  59. - (void)viewDidLoad
  60. {
  61. [super viewDidLoad];
  62. }
  63. - (void)viewWillAppear:(BOOL)animated
  64. {
  65. [super viewWillAppear:animated];
  66. }
  67. - (void)didReceiveMemoryWarning
  68. {
  69. [super didReceiveMemoryWarning];
  70. // Dispose of any resources that can be recreated.
  71. }
  72. #pragma mark ---------tableView协议----------------
  73. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  74. {
  75. return 1;
  76. }
  77. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  78. {
  79. return [_array count]+1;
  80. }
  81. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  82. {
  83. UITableViewCell *cell=nil;
  84. NSString* cellName = [NSString stringWithFormat:@"msg_%d_%ld",_refreshCount,indexPath.row];
  85. cell = [tableView dequeueReusableCellWithIdentifier:cellName];
  86. if(cell==nil){
  87. cell = [UITableViewCell alloc];
  88. [_table addToPool:cell];
  89. cell = [cell initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
  90. UILabel* p = [[UILabel alloc]initWithFrame:CGRectMake(20, 0, 300, row_height)];
  91. if(indexPath.row==0)
  92. p.text = parentName;
  93. else
  94. p.text = [_array objectForKey:[_keys objectAtIndex:indexPath.row-1]];
  95. p.font = g_factory.font16;
  96. [cell addSubview:p];
  97. // [p release];
  98. UIView* line = [[UIView alloc] initWithFrame:CGRectMake(18,row_height-LINE_WH,JX_SCREEN_WIDTH-18-20,LINE_WH)];
  99. line.backgroundColor = THE_LINE_COLOR;
  100. [cell addSubview:line];
  101. // [line release];
  102. if(indexPath.row>0){
  103. UIImageView* iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"more_flag"]];
  104. iv.frame = CGRectMake(JX_SCREEN_WIDTH-20, (row_height-13)/2, 7, 13);
  105. [cell addSubview:iv];
  106. // [iv release];
  107. }
  108. }
  109. return cell;
  110. }
  111. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  112. {
  113. self.selValue = self.parentName;
  114. self.selected = self.parentId;
  115. if(indexPath.row>0){
  116. self.selValue = [_array objectForKey:[_keys objectAtIndex:indexPath.row-1]];
  117. self.selected = [[_keys objectAtIndex:indexPath.row-1] intValue];
  118. self.cityId = self.selected;
  119. if(self.showArea){
  120. selectAreaVC* vc = [selectAreaVC alloc];
  121. vc.parentName = self.selValue;
  122. vc.parentId = self.selected;
  123. vc.didSelect = @selector(doSelect:);
  124. vc.delegate = self;
  125. vc = [vc init];
  126. // [g_window addSubview:vc.view];
  127. [g_navigation pushViewController:vc animated:YES];
  128. return;
  129. }
  130. }
  131. if (delegate && [delegate respondsToSelector:didSelect])
  132. // [delegate performSelector:didSelect withObject:self];
  133. [delegate performSelectorOnMainThread:didSelect withObject:self waitUntilDone:NO];
  134. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  135. [self actionQuit];
  136. });
  137. }
  138. -(void)doSelect:(selectAreaVC*)sender{
  139. if(sender.selected==sender.parentId)
  140. self.selValue = sender.selValue;
  141. else
  142. self.selValue = [NSString stringWithFormat:@"%@.%@",self.selValue,sender.selValue];
  143. self.cityId = sender.parentId;
  144. self.areaId = sender.selected;
  145. self.selected = sender.selected;
  146. if (delegate && [delegate respondsToSelector:didSelect])
  147. // [delegate performSelector:didSelect withObject:self];
  148. [delegate performSelectorOnMainThread:didSelect withObject:self waitUntilDone:NO];
  149. [self actionQuit];
  150. }
  151. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  152. {
  153. return row_height;
  154. }
  155. @end