JXMessageTableVc.m 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  1. #import <QuartzCore/QuartzCore.h>
  2. #import "JXMessageTableVc.h"
  3. #import "AppDelegate.h"
  4. //#import "myNearViewController.h"
  5. #import "JXLabel.h"
  6. #import "JXTableView.h"
  7. //#import "JXMainViewController.h"
  8. #import "MJRefreshBaseView.h"
  9. #import "UIImage+Tint.h"
  10. #import "JXSelectFriendsVC.h"
  11. #define REFRESH_HEADER_HEIGHT 60
  12. #define HEIGHT_STATUS_BAR 20
  13. #define kScreenWidth ([UIScreen mainScreen].bounds.size.width)
  14. #define kScreenHeight ([UIScreen mainScreen].bounds.size.height)
  15. #define IS_IPHONE_X (kScreenHeight == 812.0 ? YES : NO)
  16. //判断iPHoneXr
  17. #define IS_IPHONE_Xr (kScreenHeight == 896.0 ? YES : NO)
  18. //判断iPhoneXs
  19. #define IS_IPHONE_Xs (kScreenHeight == 812.0 ? YES : NO)
  20. //判断iPhoneXs Max
  21. #define IS_IPHONE_Xs_Max (kScreenHeight == 896.0 ? YES : NO)
  22. #define kTopStateHight ((IS_IPHONE_X == YES || IS_IPHONE_Xr == YES || IS_IPHONE_Xs== YES || IS_IPHONE_Xs_Max== YES) ? 44.0 : 20.0)
  23. @implementation JXMessageTableVc
  24. @synthesize heightFooter,heightHeader,tableHeader,tableFooter,isGotoBack,footerBtnLeft,footerBtnMid,footerBtnRight,headerTitle,isFreeOnClose,isShowHeaderPull,isShowFooterPull,tableView=_table;
  25. @synthesize header=_header;
  26. @synthesize footer=_footer;
  27. - (id)init{
  28. self = [super initWithNibName:nil bundle:nil];
  29. if (self != nil) {
  30. [self setupStrings];
  31. }
  32. return self;
  33. }
  34. //- (id)initWithStyle:(UITableViewStyle)style {
  35. // self = [super initWithStyle:style];
  36. // if (self != nil) {
  37. // [self setupStrings];
  38. // }
  39. // return self;
  40. //}
  41. - (id)initWithCoder:(NSCoder *)aDecoder {
  42. self = [super initWithCoder:aDecoder];
  43. if (self != nil) {
  44. [self setupStrings];
  45. }
  46. return self;
  47. }
  48. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
  49. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  50. if (self != nil) {
  51. [self setupStrings];
  52. }
  53. return self;
  54. }
  55. - (void)loadView
  56. {
  57. [super loadView];
  58. [self createTableView];
  59. [[self view] addSubview:_table];
  60. _table.backgroundColor=kRGBColor250;
  61. self.view.backgroundColor=kRGBColor250;
  62. }
  63. -(void)createTableView{
  64. if(_table == nil){
  65. // CGRect frame = CGRectMake(0, -70, self.view.frame.size.width, self.view.frame.size.height - 49);
  66. //_table = [[JXTableView alloc] initWithFrame:CGRectMake(0, JX_SCREEN_HEIGHT>=812?88:64, JX_SCREEN_WIDTH,
  67. _table = [[JXTableView alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT-(JX_SCREEN_HEIGHT>=812?88:64)) style:UITableViewStylePlain];
  68. //_table.frame =CGRectMake(0,0,self_width,self_height-0-heightFooter);
  69. _table.touchDelegate = self;
  70. _table.delegate = self;
  71. _table.dataSource = self;
  72. _table.backgroundColor = [UIColor whiteColor];
  73. _table.separatorStyle = UITableViewCellSeparatorStyleNone;
  74. _table.sectionIndexColor = [UIColor grayColor]; //修改右边索引字体的颜色
  75. _table.sectionIndexBackgroundColor = [UIColor clearColor];
  76. [_table setAutoresizesSubviews:YES];
  77. [_table setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
  78. _table.estimatedRowHeight = 0;
  79. _table.estimatedSectionFooterHeight = 0;
  80. _table.estimatedSectionHeaderHeight = 0;
  81. [self.view addSubview:_table];
  82. [self addFooter];
  83. [self addHeader];
  84. }
  85. }
  86. - (void)clickNewAdd:(UIButton *)btn{
  87. [g_navigation dismissViewController:self animated:YES];
  88. }
  89. //消息进去群组
  90. - (void)clickNewAdd2:(UIButton *)btn{
  91. [self.navigationController popViewControllerAnimated:YES];
  92. }
  93. //===========================聊天界面push下个控制器的头部==================================
  94. -(void)defineNavChatPush:(NSString *)title
  95. {
  96. UIView *navView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH,JX_SCREEN_HEIGHT>=812?88:64)];
  97. navView.backgroundColor = [UIColor whiteColor];
  98. [self.view addSubview:navView];
  99. UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  100. backBtn.frame = CGRectMake(0,kTopStateHight,50, 44);
  101. [backBtn setImage:[UIImage imageNamed:@"title_back_black"] forState:0];
  102. //backBtn.imageEdgeInsets =UIEdgeInsetsMake(13,15,13,25);
  103. backBtn.tag = 1001;
  104. [backBtn addTarget:self action:@selector(clickNewAdd:) forControlEvents:UIControlEventTouchUpInside];
  105. [navView addSubview:backBtn];
  106. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50,kTopStateHight+12, kScreenWidth-100, 20)];
  107. label.text = title;
  108. label.textColor =[UIColor blackColor];
  109. label.textAlignment = NSTextAlignmentCenter;
  110. label.font=[UIFont systemFontOfSize:18 weight:UIFontWeightMedium];
  111. [navView addSubview:label];
  112. }
  113. -(void)defineNavPushAbbGoundBar3:(NSString *)title and:(NSString *)btnIMG
  114. {
  115. UIView *navView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH,JX_SCREEN_HEIGHT>=812?44:44)];
  116. navView.backgroundColor = [UIColor whiteColor];
  117. [self.view addSubview:navView];
  118. UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  119. backBtn.frame = CGRectMake(0,0,50, 44);
  120. [backBtn setImage:[UIImage imageNamed:@"title_back_black"] forState:0];
  121. //backBtn.imageEdgeInsets =UIEdgeInsetsMake(13,15,13,25);
  122. backBtn.tag = 1001;
  123. [backBtn addTarget:self action:@selector(clickNewAdd2:) forControlEvents:UIControlEventTouchUpInside];
  124. [navView addSubview:backBtn];
  125. [navView addSubview:backBtn];
  126. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50,0, kScreenWidth-100, 44)];
  127. label.text = title;
  128. label.textColor =[UIColor blackColor];
  129. label.textAlignment = NSTextAlignmentCenter;
  130. label.font=[UIFont systemFontOfSize:18 weight:UIFontWeightMedium];
  131. [navView addSubview:label];
  132. UIButton *addFriend = [UIButton buttonWithType:UIButtonTypeCustom];
  133. addFriend.frame = CGRectMake(JX_SCREEN_WIDTH-55,0,44, 44);
  134. [addFriend setImage:[UIImage imageNamed:btnIMG] forState:0];
  135. //addFriend.imageEdgeInsets =UIEdgeInsetsMake(13,15,13,25);
  136. addFriend.tag = 1002;
  137. [addFriend addTarget:self action:@selector(addFriendCLickk) forControlEvents:UIControlEventTouchUpInside];
  138. [navView addSubview:addFriend];
  139. }
  140. -(void)defineNavPushAbbGoundBar2:(NSString *)title and:(NSString *)btnIMG
  141. {
  142. UIView *navView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH,JX_SCREEN_HEIGHT>=812?88:64)];
  143. navView.backgroundColor = [UIColor whiteColor];
  144. [self.view addSubview:navView];
  145. UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  146. backBtn.frame = CGRectMake(0,kTopStateHight,50, 44);
  147. [backBtn setImage:[UIImage imageNamed:@"title_back_black"] forState:0];
  148. backBtn.imageEdgeInsets =UIEdgeInsetsMake(13,15,13,25);
  149. backBtn.tag = 1001;
  150. if ([btnIMG isEqualToString:@"im_003_more_button_black"]) {
  151. [backBtn addTarget:self action:@selector(clickNewAdd2:) forControlEvents:UIControlEventTouchUpInside];
  152. [navView addSubview:backBtn];
  153. }else{
  154. [backBtn addTarget:self action:@selector(clickNewAdd:) forControlEvents:UIControlEventTouchUpInside];
  155. }
  156. [navView addSubview:backBtn];
  157. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50,kTopStateHight+12, kScreenWidth-100, 20)];
  158. label.text = title;
  159. label.textColor =[UIColor blackColor];
  160. label.textAlignment = NSTextAlignmentCenter;
  161. label.font=[UIFont systemFontOfSize:18 weight:UIFontWeightMedium];
  162. [navView addSubview:label];
  163. UIButton *addFriend = [UIButton buttonWithType:UIButtonTypeCustom];
  164. addFriend.frame = CGRectMake(JX_SCREEN_WIDTH-55,kTopStateHight,44, 44);
  165. [addFriend setImage:[UIImage imageNamed:btnIMG] forState:0];
  166. //addFriend.imageEdgeInsets =UIEdgeInsetsMake(13,15,13,25);
  167. addFriend.tag = 1002;
  168. [addFriend addTarget:self action:@selector(addFriendCLickk) forControlEvents:UIControlEventTouchUpInside];
  169. [navView addSubview:addFriend];
  170. }
  171. //=====================================================================
  172. -(void)defineNavBar1:(NSString *)title
  173. {
  174. UIView *navView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH,JX_SCREEN_HEIGHT>=812?88:64)];
  175. navView.backgroundColor = [UIColor whiteColor];
  176. [self.view addSubview:navView];
  177. UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  178. backBtn.frame = CGRectMake(0,kTopStateHight,50, 44);
  179. [backBtn setImage:[UIImage imageNamed:@"title_back_black"] forState:0];
  180. backBtn.imageEdgeInsets =UIEdgeInsetsMake(13,15,13,25);
  181. backBtn.tag = 1001;
  182. [backBtn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
  183. [navView addSubview:backBtn];
  184. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50,kTopStateHight+12, kScreenWidth-100, 20)];
  185. label.text = title;
  186. label.textColor =[UIColor blackColor];
  187. label.textAlignment = NSTextAlignmentCenter;
  188. label.font=[UIFont systemFontOfSize:18 weight:UIFontWeightMedium];
  189. [navView addSubview:label];
  190. }
  191. -(void)defineNavBar2:(NSString *)title and:(NSString *)btnIMG
  192. {
  193. UIView *navView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH,JX_SCREEN_HEIGHT>=812?88:64)];
  194. navView.backgroundColor = [UIColor whiteColor];
  195. [self.view addSubview:navView];
  196. UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  197. backBtn.frame = CGRectMake(0,kTopStateHight,50, 44);
  198. [backBtn setImage:[UIImage imageNamed:@"title_back_black"] forState:0];
  199. backBtn.imageEdgeInsets =UIEdgeInsetsMake(13,15,13,25);
  200. backBtn.tag = 1001;
  201. [backBtn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
  202. [navView addSubview:backBtn];
  203. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50,kTopStateHight+12, kScreenWidth-100, 20)];
  204. label.text = title;
  205. label.textColor =[UIColor blackColor];
  206. label.textAlignment = NSTextAlignmentCenter;
  207. label.font=[UIFont systemFontOfSize:18 weight:UIFontWeightMedium];
  208. [navView addSubview:label];
  209. UIButton *addFriend = [UIButton buttonWithType:UIButtonTypeCustom];
  210. addFriend.frame = CGRectMake(JX_SCREEN_WIDTH-55,kTopStateHight,44, 44);
  211. [addFriend setImage:[UIImage imageNamed:btnIMG] forState:0];
  212. //addFriend.imageEdgeInsets =UIEdgeInsetsMake(13,15,13,25);
  213. addFriend.tag = 1002;
  214. [addFriend addTarget:self action:@selector(addFriendCLickk) forControlEvents:UIControlEventTouchUpInside];
  215. [navView addSubview:addFriend];
  216. }
  217. - (void)addFriendCLickk{
  218. if ([g_config.isCommonCreateGroup intValue] == 1) {
  219. [g_App showAlert:Localized(@"JX_NotCreateNewRoom")];
  220. return;
  221. }
  222. // JXNewRoomVC* vc = [[JXNewRoomVC alloc]init];
  223. // [g_navigation pushViewController:vc animated:YES];
  224. JXSelectFriendsVC *vc = [JXSelectFriendsVC alloc];
  225. vc.isPlusButtonComming = YES;
  226. vc = [vc init];
  227. [g_navigation pushViewController:vc animated:YES];
  228. }
  229. - (void)click:(UIButton *)sender
  230. {
  231. [self.navigationController popViewControllerAnimated:YES];
  232. return;
  233. [g_App.navigation dismissViewController:self animated:YES];
  234. }
  235. - (void)viewWillAppear:(BOOL)animated{
  236. [super viewWillAppear:animated];
  237. [self.navigationController setNavigationBarHidden:YES animated:NO];
  238. }
  239. - (void)viewWillDisappear:(BOOL)animated{
  240. [super viewWillDisappear:animated];
  241. [self.navigationController setNavigationBarHidden:NO animated:NO];
  242. }
  243. - (void)viewDidLoad {
  244. [super viewDidLoad];
  245. if (self.isGotoBack) {
  246. //self.view.frame = CGRectMake(JX_SCREEN_WIDTH, 0, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT);
  247. [self screenEdgePanGestureRecognizer];
  248. }
  249. //设置分割线
  250. // if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
  251. // [self.tableView setSeparatorInset:UIEdgeInsetsMake(0, 10, 0, 10)];
  252. // }
  253. // if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
  254. // [self.tableView setLayoutMargins:UIEdgeInsetsMake(0, 10, 0, 10)];
  255. // }
  256. _wait = [ATMHud sharedInstance];
  257. }
  258. //创建边缘手势
  259. -(void)screenEdgePanGestureRecognizer
  260. {
  261. UIScreenEdgePanGestureRecognizer *screenPan = [[UIScreenEdgePanGestureRecognizer alloc]initWithTarget:self action:@selector(screenPanAction:)];
  262. screenPan.edges = UIRectEdgeLeft;
  263. [self.view addGestureRecognizer:screenPan];
  264. [self.tableView.panGestureRecognizer requireGestureRecognizerToFail:screenPan];
  265. }
  266. //边缘手势事件
  267. -(void)screenPanAction:(UIScreenEdgePanGestureRecognizer *)screenPan
  268. {
  269. return;
  270. CGPoint p = [screenPan translationInView:self.view];
  271. NSLog(@"p = %@",NSStringFromCGPoint(p));
  272. self.view.frame = CGRectMake(p.x, 0, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT);
  273. if (screenPan.state == UIGestureRecognizerStateEnded) {
  274. if (p.x > JX_SCREEN_WIDTH/2) {
  275. [self actionQuit];
  276. }else {
  277. [self resetViewFrame];
  278. }
  279. }
  280. }
  281. //- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  282. //{
  283. //
  284. // if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  285. // [cell setSeparatorInset:UIEdgeInsetsMake(0, 10, 0, 10)];
  286. // }
  287. // if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
  288. // [cell setLayoutMargins:UIEdgeInsetsMake(0, 10, 0, 10)];
  289. // }
  290. //}
  291. - (void)setupStrings{
  292. // _pSelf = self;
  293. _oldRowCount = 0;
  294. _lastScrollTime = 0;
  295. _isLoading = NO;
  296. heightHeader=JX_SCREEN_TOP;
  297. heightFooter=JX_SCREEN_BOTTOM;
  298. isFreeOnClose = YES;
  299. [g_window endEditing:YES];
  300. // if(isIOS7){
  301. // self.view.frame = CGRectMake(0, -20, self.view.frame.size.width, self.view.frame.size.height);
  302. // }
  303. }
  304. - (void)objectDidDragged:(UIPanGestureRecognizer *)sender {
  305. if (sender.state == UIGestureRecognizerStateEnded){
  306. CGPoint offset = [sender translationInView:g_App.window];
  307. if(offset.y>20 || offset.y<-20)
  308. return;
  309. if(isGotoBack)
  310. [self actionQuit];
  311. else
  312. [self onGotoHome];
  313. }
  314. /*
  315. if (sender.state == UIGestureRecognizerStateChanged ||
  316. sender.state == UIGestureRecognizerStateEnded) {
  317. //注意,这里取得的参照坐标系是该对象的上层View的坐标。
  318. CGPoint offset = [sender translationInView:g_App.window];
  319. //通过计算偏移量来设定draggableObj的新坐标
  320. [self.view setCenter:CGPointMake(self.view.center.x + offset.x, self.view.center.y + offset.y)];
  321. //初始化sender中的坐标位置。如果不初始化,移动坐标会一直积累起来。
  322. [sender setTranslation:CGPointMake(0, 0) inView:g_App.window];
  323. }
  324. */
  325. }
  326. - (void)stopLoading {
  327. _isLoading = NO;
  328. [_footer endRefreshing];
  329. [_header endRefreshing];
  330. }
  331. - (void)dealloc {
  332. NSLog(@"dealloc - %@",[self class]);
  333. [_header free];
  334. [_footer free];
  335. tableHeader = nil;
  336. tableFooter = nil;
  337. _footer = nil;
  338. _header = nil;
  339. self.title = nil;
  340. self.headerTitle = nil;
  341. // _table = nil;
  342. // [super dealloc];
  343. }
  344. -(void)createHeaderView{
  345. tableHeader = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self_width, heightHeader)];
  346. UIImageView* iv = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self_width, heightHeader)];
  347. if (THESIMPLESTYLE) {
  348. iv.image = [[UIImage imageNamed:@"navBarBackground"] imageWithTintColor:[UIColor whiteColor]];
  349. }else {
  350. iv.image = [g_theme themeTintImage:@"navBarBackground"];//[UIImage imageNamed:@"navBarBackground"];
  351. }
  352. iv.userInteractionEnabled = YES;
  353. [tableHeader addSubview:iv];
  354. // [iv release];
  355. JXLabel* p = [[JXLabel alloc]initWithFrame:CGRectMake(40, JX_SCREEN_TOP - 15-17, self_width-40*2, 20)];
  356. p.backgroundColor = [UIColor clearColor];
  357. p.textAlignment = NSTextAlignmentCenter;
  358. p.textColor = THESIMPLESTYLE ? [UIColor blackColor] : [UIColor whiteColor];
  359. p.text = self.title;
  360. p.font = [UIFont systemFontOfSize:18.0];
  361. p.userInteractionEnabled = YES;
  362. p.didTouch = @selector(actionTitle:);
  363. p.delegate = self;
  364. p.changeAlpha = NO;
  365. [tableHeader addSubview:p];
  366. // [p release];
  367. self.headerTitle = p;
  368. if(isGotoBack){
  369. self.gotoBackBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, JX_SCREEN_TOP - 46, 46, 46)];
  370. [self.gotoBackBtn setBackgroundImage:[UIImage imageNamed:@"title_back_black_big"] forState:UIControlStateNormal];
  371. [self.gotoBackBtn addTarget:self action:@selector(actionQuit) forControlEvents:UIControlEventTouchUpInside];
  372. [self.gotoBackBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  373. self.gotoBackBtn.titleLabel.font = [UIFont systemFontOfSize:15.0];
  374. self.gotoBackBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 0);
  375. [self.tableHeader addSubview:self.gotoBackBtn];
  376. }
  377. }
  378. -(void)createFooterView{
  379. tableFooter = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self_width, heightFooter)];
  380. tableFooter.backgroundColor = HEXCOLOR(0xF2F2F2);;
  381. // UIView* line = [[UIView alloc]initWithFrame:CGRectMake(0,0,JX_SCREEN_WIDTH,LINE_WH)];
  382. // line.backgroundColor = THE_LINE_COLOR;
  383. // [tableFooter addSubview:line];
  384. // [line release];
  385. UIButton* btn;
  386. if(isGotoBack)
  387. return;
  388. btn = [UIButton buttonWithType:UIButtonTypeCustom];
  389. btn.frame = CGRectMake((self_width-76)/2, (49-36)/2, 152/2, 72/2);
  390. [btn setBackgroundImage:[UIImage imageNamed:@"singing_button_normal"] forState:UIControlStateNormal];
  391. [btn setBackgroundImage:[UIImage imageNamed:@"singing_button_press"] forState:UIControlStateHighlighted];
  392. [btn addTarget:self action:@selector(onSing) forControlEvents:UIControlEventTouchUpInside];
  393. [tableFooter addSubview:btn];
  394. self.footerBtnMid = btn;
  395. btn = [UIButton buttonWithType:UIButtonTypeCustom];
  396. btn.frame = CGRectMake(self_width-53-5, (49-33)/2, 53, 66/2);
  397. [btn setBackgroundImage:[UIImage imageNamed:@"nearby_button_normal"] forState:UIControlStateNormal];
  398. [btn setBackgroundImage:[UIImage imageNamed:@"nearby_button_press"] forState:UIControlStateHighlighted];
  399. [btn addTarget:self action:@selector(onBtnRight) forControlEvents:UIControlEventTouchUpInside];
  400. [tableFooter addSubview:btn];
  401. self.footerBtnRight = btn;
  402. self.footerBtnRight.hidden = YES;
  403. }
  404. -(JXTableView*)getTableView{
  405. return _table;
  406. }
  407. -(void)createHeadAndFoot{
  408. if(heightHeader==0 && heightFooter==0)
  409. return;
  410. int heightTotal = self.view.frame.size.height;
  411. [self.view addSubview:_table];
  412. if(heightHeader>0){
  413. // [self createHeaderView];
  414. // [self.view addSubview:tableHeader];
  415. // [tableHeader release];
  416. }
  417. if(heightFooter>0){
  418. [self createFooterView];
  419. [self.view addSubview:tableFooter];
  420. // [tableFooter release];
  421. tableFooter.frame = CGRectMake(0,heightTotal-heightFooter,self_width,heightFooter);
  422. }
  423. //_table.frame =CGRectMake(0,heightHeader,self_width,self_height-heightHeader-heightFooter);
  424. _table.frame =CGRectMake(0,0,self_width,self_height-0-heightFooter);
  425. }
  426. -(void) onGotoHome{
  427. // if(self.view.frame.origin.x == 260){
  428. // [g_App.leftView onClick];
  429. // return;
  430. // }
  431. CGContextRef context = UIGraphicsGetCurrentContext();
  432. [UIView beginAnimations:nil context:context];
  433. [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
  434. [UIView setAnimationDuration:0.3];
  435. // self.view.frame = CGRectMake (260, 0, self_width, self.view.frame.size.height);
  436. g_App.mainVc.view.frame = CGRectMake (260, 0, g_App.mainVc.view.frame.size.width, g_App.mainVc.view.frame.size.height);
  437. [UIView commitAnimations];
  438. }
  439. -(void)actionQuit{
  440. [_wait stop];
  441. [g_server stopConnection:self];
  442. [g_window endEditing:YES];
  443. [g_notify removeObserver:self];
  444. [_header removeFromSuperview];
  445. [_footer removeFromSuperview];
  446. _header = nil;
  447. _footer = nil;
  448. // CGContextRef context = UIGraphicsGetCurrentContext();
  449. // [UIView beginAnimations:nil context:context];
  450. // [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
  451. // [UIView setAnimationDuration:0.2];
  452. // [UIView setAnimationDelegate:self];
  453. // [UIView setAnimationDidStopSelector:@selector(doQuit)];
  454. [g_navigation dismissViewController:self animated:YES];
  455. // self.view.frame = CGRectMake (JX_SCREEN_WIDTH, 0, self_width, self.view.frame.size.height);
  456. // NSInteger index = g_window.subviews.count;
  457. // if (index - 2 >= 0) {
  458. // UIView *view = g_window.subviews[index - 2];
  459. // view.frame = CGRectMake (0, 0, self_width, self.view.frame.size.height);
  460. // }
  461. // [UIView commitAnimations];
  462. }
  463. -(void)doQuit{
  464. [self.view removeFromSuperview];
  465. // if(isFreeOnClose)
  466. // _pSelf = nil;
  467. }
  468. -(void)onSing{
  469. // [g_App.leftView onSing];
  470. }
  471. -(void)onBtnRight{
  472. // [g_App.leftView onNear];
  473. }
  474. -(void)actionTitle:(JXLabel*)sender{
  475. }
  476. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  477. {
  478. return (interfaceOrientation == UIInterfaceOrientationPortrait);
  479. }
  480. //顶部刷新获取数据
  481. -(void)scrollToPageUp{
  482. if(_isLoading)
  483. return;
  484. NSLog(@"scrollToPageUp");
  485. _page = 0;
  486. [self getServerData];
  487. [self performSelector:@selector(stopLoading) withObject:nil afterDelay:1.0];
  488. }
  489. -(void)scrollToPageDown{
  490. if(_isLoading)
  491. return;
  492. _page++;
  493. [self getServerData];
  494. }
  495. -(void)setIsShowHeaderPull:(BOOL)b{
  496. _header.hidden = !b;
  497. isShowHeaderPull = b;
  498. }
  499. -(void)setIsShowFooterPull:(BOOL)b{
  500. _footer.hidden = !b;
  501. isShowFooterPull = b;
  502. }
  503. -(void)getServerData{
  504. }
  505. - (void)addFooter
  506. {
  507. if(_footer){
  508. // [_footer free];
  509. // return;
  510. }
  511. _footer = [MJRefreshFooterView footer];
  512. _footer.scrollView = _table;
  513. __weak JXTableViewController *weakSelf = self;
  514. _footer.beginRefreshingBlock = ^(MJRefreshBaseView *refreshView) {
  515. [weakSelf scrollToPageDown];
  516. // NSLog(@"%@----开始进入刷新状态", refreshView.class);
  517. };
  518. _footer.endStateChangeBlock = ^(MJRefreshBaseView *refreshView) {
  519. // 刷新完毕就会回调这个Block
  520. // NSLog(@"%@----刷新完毕", refreshView.class);
  521. };
  522. _footer.refreshStateChangeBlock = ^(MJRefreshBaseView *refreshView, MJRefreshState state) {
  523. // 控件的刷新状态切换了就会调用这个block
  524. switch (state) {
  525. case MJRefreshStateNormal:
  526. // NSLog(@"%@----切换到:普通状态", refreshView.class);
  527. break;
  528. case MJRefreshStatePulling:
  529. // NSLog(@"%@----切换到:松开即可刷新的状态", refreshView.class);
  530. break;
  531. case MJRefreshStateRefreshing:
  532. // NSLog(@"%@----切换到:正在刷新状态", refreshView.class);
  533. break;
  534. default:
  535. break;
  536. }
  537. };
  538. }
  539. - (void)addHeader
  540. {
  541. if(_header){
  542. // [_header free];
  543. // return;
  544. }
  545. _header = [MJRefreshHeaderView header];
  546. _header.scrollView = _table;
  547. __weak JXTableViewController *weakSelf = self;
  548. _header.beginRefreshingBlock = ^(MJRefreshBaseView *refreshView) {
  549. // 进入刷新状态就会回调这个Block
  550. [weakSelf scrollToPageUp];
  551. };
  552. _header.endStateChangeBlock = ^(MJRefreshBaseView *refreshView) {
  553. // 刷新完毕就会回调这个Block
  554. // NSLog(@"%@----刷新完毕", refreshView.class);
  555. };
  556. _header.refreshStateChangeBlock = ^(MJRefreshBaseView *refreshView, MJRefreshState state) {
  557. // 控件的刷新状态切换了就会调用这个block
  558. switch (state) {
  559. case MJRefreshStateNormal:
  560. // NSLog(@"%@----切换到:普通状态", refreshView.class);
  561. break;
  562. case MJRefreshStatePulling:
  563. // NSLog(@"%@----切换到:松开即可刷新的状态", refreshView.class);
  564. break;
  565. case MJRefreshStateRefreshing:
  566. // NSLog(@"%@----切换到:正在刷新状态", refreshView.class);
  567. break;
  568. default:
  569. break;
  570. }
  571. };
  572. }
  573. -(void)setTitle:(NSString *)value{
  574. self.headerTitle.text = value;
  575. [super setTitle:value];
  576. }
  577. //左移页面
  578. - (void)moveSelfViewToLeft{
  579. [UIView animateWithDuration:0.3 animations:^{
  580. self.view.frame = CGRectMake(-85, 0, JX_SCREEN_WIDTH, self.view.frame.size.height);
  581. }];
  582. }
  583. //归位
  584. - (void)resetViewFrame{
  585. [UIView animateWithDuration:0.3 animations:^{
  586. self.view.frame = CGRectMake(0, 0, JX_SCREEN_WIDTH, self.view.frame.size.height);
  587. }];
  588. }
  589. -(void)doAutoScroll:(NSIndexPath*)indexPath{
  590. if(_oldRowCount == [self tableView:_table numberOfRowsInSection:indexPath.section])//说明翻页之后,数据没有增长,则不再自动翻页,但可手动翻页
  591. return;
  592. if([[NSDate date] timeIntervalSince1970]-_lastScrollTime<0.5)//避免刷新过快
  593. return;
  594. if(isShowHeaderPull && !isShowFooterPull){//如果只有向上翻页
  595. if(indexPath.row == 0){
  596. _oldRowCount = (int)[self tableView:_table numberOfRowsInSection:indexPath.section];
  597. NSLog(@"doAutoScroll=%d",_oldRowCount);
  598. [self scrollToPageUp];
  599. _lastScrollTime = [[NSDate date] timeIntervalSince1970];
  600. // _isLoading = YES;
  601. return;
  602. }
  603. }
  604. if(isShowFooterPull){//如果有向下翻页
  605. if(indexPath.row == [self tableView:_table numberOfRowsInSection:indexPath.section]-1){
  606. _oldRowCount = (int)[self tableView:_table numberOfRowsInSection:indexPath.section];
  607. NSLog(@"doAutoScroll=%d",_oldRowCount);
  608. [self scrollToPageDown];
  609. // _isLoading = YES;
  610. _lastScrollTime = [[NSDate date] timeIntervalSince1970];
  611. return;
  612. }
  613. }
  614. }
  615. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  616. return 0;
  617. }
  618. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  619. return [[UITableViewCell alloc] init];
  620. }
  621. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  622. // 防止重复点击
  623. tableView.userInteractionEnabled = NO;
  624. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  625. tableView.userInteractionEnabled = YES;
  626. });
  627. }
  628. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
  629. [self.view endEditing:YES];
  630. }
  631. @end