LearnDrivingVC.m 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. #import "LearnDrivingVC.h"
  2. #import "MyUINavigationController.h"
  3. #import "CommunityVC.h"
  4. #import "DiaryVC.h"
  5. #import "CLCell.h"
  6. #import "LoginViewController.h"
  7. #import "TopicesVC.h"
  8. #import "NewsOfLearnVC.h"
  9. //#import "RecordOfLearnVC.h"
  10. #import "GuideVC.h"
  11. #import "CoachDetailInfoVC.h"
  12. #import "ShareVC.h"
  13. @interface LearnDrivingVC ()<UITableViewDataSource,UITableViewDelegate>
  14. {
  15. UITableView* myTableView;
  16. NSMutableArray* titles;
  17. NSMutableArray* images;
  18. NSMutableArray* details;
  19. NSMutableArray *countArray;
  20. }
  21. @end
  22. @implementation LearnDrivingVC
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. [self myInit];
  26. }
  27. - (void)didReceiveMemoryWarning {
  28. [super didReceiveMemoryWarning];
  29. // Dispose of any resources that can be recreated
  30. }
  31. -(void)viewWillAppear:(BOOL)animated
  32. {
  33. [super viewWillAppear:animated];
  34. [self getCurrentTopicTj];
  35. }
  36. -(void)viewWillDisappear:(BOOL)animated{
  37. [self setHidesBottomBarWhenPushed:NO];
  38. [super viewWillDisappear:animated];
  39. }
  40. #pragma mark -
  41. -(void)myInit
  42. {
  43. self.navigationItem.title = @"学车社区";
  44. [self.view setBackgroundColor:backGroundColor];
  45. countArray = [NSMutableArray alloc];
  46. titles = [NSMutableArray array];
  47. images = [NSMutableArray array];
  48. details = [NSMutableArray array];
  49. NSArray* arr;
  50. arr = @[@"驾考社区",@"驾考头条",@"学车指南"];
  51. [titles addObject:arr];
  52. arr = @[@"学车记录",@"学车问答",@"我的学车日记"];//@"学车直播",
  53. [titles addObject:arr];
  54. arr = @[@"我的教练"];
  55. [titles addObject:arr];
  56. arr = @[@"learn_img01.png",@"learn_img02.png",@"learn_img03.png"];
  57. [images addObject:arr];
  58. arr = @[@"learn_img04.png",@"learn_img06.png"];
  59. [images addObject:arr];
  60. arr = @[@"learn_img07.png",@"learn_img08.png",@"learn_img09.png"];
  61. [images addObject:arr];
  62. arr = @[[NSString stringWithFormat:@"%d人参与讨论",arc4random()%100],[NSString stringWithFormat:@"%d万人正在关注",arc4random()%7],@"",@"",@""];
  63. [details addObject:arr];
  64. arr = @[[NSString stringWithFormat:@"有%d人在学车",arc4random()%100],[NSString stringWithFormat:@"有%d人参与问答",arc4random()%100],@"",@""];//,[NSString stringWithFormat:@"有%d人参与直播",arc4random()%100]
  65. [details addObject:arr];
  66. arr = @[@"",@"",@""];
  67. [details addObject:arr];
  68. myTableView = [[UITableView alloc] initWithFrame:kFrame style:UITableViewStyleGrouped];
  69. myTableView.height -= kTabBarHeight;
  70. [self.view addSubview:myTableView];
  71. [myTableView setDelegate:self];
  72. [myTableView setDataSource:self];
  73. myTableView.estimatedSectionHeaderHeight = 0;
  74. myTableView.estimatedSectionFooterHeight = 0;
  75. }
  76. #pragma mark -
  77. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  78. {
  79. return .1;
  80. }
  81. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  82. {
  83. return 10;
  84. }
  85. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  86. {
  87. return titles.count;
  88. }
  89. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  90. {
  91. NSArray *array = titles[section];
  92. return [array count];
  93. }
  94. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  95. {
  96. NSString* reuseID = @"learningCell";
  97. UITableViewCell* cell;
  98. if (!cell) {
  99. cell = [[CLCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuseID];
  100. [cell.detailTextLabel setFont:[UIFont scaleSize:13]];
  101. [cell.textLabel setTextColor:contentTextColor];
  102. [cell.textLabel setFont:[UIFont scaleSize:15]];
  103. }
  104. [cell.textLabel setText:[titles objAtPath:indexPath] ];
  105. if (indexPath.section == 1 && indexPath.row == 2)
  106. {
  107. [cell.textLabel setTextAlignment:NSTextAlignmentCenter];
  108. [cell.textLabel setTextColor:contentTextColor];
  109. return cell;
  110. }
  111. [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
  112. UIImage* img = [UIImage imageNamed:[images objAtPath:indexPath] ];
  113. [cell.imageView setImage:img];
  114. [cell.detailTextLabel setText:[details objAtPath:indexPath] ];
  115. return cell;
  116. }
  117. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  118. {
  119. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  120. if (0 == indexPath.section) {
  121. if (0 == indexPath.row) {
  122. CommunityVC* vc = [[CommunityVC alloc] init];
  123. [self navPushHideTabbarToVC:vc];
  124. }
  125. if (1 == indexPath.row) {
  126. // ShareVC* vc = [[ShareVC alloc] init];
  127. // [self navPushHideTabbarToVC:vc];
  128. // 驾考头条 这里改为驾考新闻 直接进入新闻页面
  129. NewsOfLearnVC* vc = [[NewsOfLearnVC alloc] init];
  130. [self navPushHideTabbarToVC:vc];
  131. }
  132. if (2 == indexPath.row) {
  133. GuideVC* vc = [[GuideVC alloc] init];
  134. [self navPushHideTabbarToVC:vc];
  135. }
  136. }
  137. if (1 == indexPath.section)
  138. {
  139. if (0 == indexPath.row) {
  140. // RecordOfLearnVC* vc = [[RecordOfLearnVC alloc] init];
  141. TopicesVC* vc = [[TopicesVC alloc] init];
  142. vc.type = @"2";
  143. vc.groupId = @"";
  144. vc.childID = @"";
  145. [self navPushHideTabbarToVC:vc];
  146. }
  147. // if (1 == indexPath.row) {
  148. // TopicesVC* vc = [[TopicesVC alloc] init];
  149. // vc.type = @"3";
  150. // [self navPushHideTabbarToVC:vc];
  151. // }
  152. if (1 == indexPath.row) {
  153. TopicesVC* vc = [[TopicesVC alloc] init];
  154. vc.type = @"4";
  155. [self navPushHideTabbarToVC:vc];
  156. }
  157. if (2 == indexPath.row)
  158. {
  159. if (!myDelegate.isLogin) {
  160. [LoginViewController loginFromVC:self];
  161. return;
  162. }
  163. DiaryVC* vc = [[DiaryVC alloc] init];
  164. vc.userID = defUser.userDict[@"id"];
  165. [self navPushHideTabbarToVC:vc];
  166. }
  167. }
  168. if (2 == indexPath.section) {
  169. if (myDelegate.isLogin) {
  170. CoachDetailInfoVC* vc = [[CoachDetailInfoVC alloc] init];
  171. MyUINavigationController* nav = [[MyUINavigationController alloc] initWithRootViewController:vc];
  172. nav.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
  173. nav.modalPresentationStyle = UIModalPresentationFullScreen;
  174. [self.parentViewController presentViewController:nav animated:YES completion:nil];
  175. }else{
  176. ShowMsg(@"请登录后再操作!");
  177. [LoginViewController loginFromVC:self];
  178. }
  179. }
  180. }
  181. #pragma mark -
  182. /**
  183. */
  184. -(void)getCurrentTopicTj
  185. {
  186. if (![Util connectedToNetWork]) {
  187. showMsgUnconnect();
  188. return;
  189. }
  190. NSString* method = @"getCurrentTopicTj";
  191. [jiaPeiManager requestGetAnythingWithURL:method completion:^(NSDictionary *dict) {
  192. //NSLog(@"getCurrentTopicTj%@",dict);
  193. if (!dict) {
  194. ShowMsgFailed();
  195. return;
  196. }
  197. if ([dict[@"code"] isEqualToString:@"1"]) {
  198. ShowMsg(dict[@"body"]);
  199. return;
  200. }
  201. NSDictionary *dic = dict[@"body"];
  202. if (dic && [[dic allKeys] count] > 0)
  203. {
  204. [details removeAllObjects];
  205. NSArray *arr;
  206. arr = @[[NSString stringWithFormat:@"%@人参与话题",[self isWan:dic[@"COMMENTNUM"]]],[NSString stringWithFormat:@"%@人正在关注",[self isWan:dic[@"READNUM"]]],@"",@"",@""];
  207. if ([dic[@"COMMENTNUM"] isEqualToString:@""])
  208. {
  209. arr = @[[NSString stringWithFormat:@"0人参与话题"],[NSString stringWithFormat:@"%@人正在关注",[self isWan:dic[@"READNUM"]]],@"",@"",@""];
  210. if ([dic[@"READNUM"] isEqualToString:@""])
  211. {
  212. arr = @[[NSString stringWithFormat:@"0人参与话题"],[NSString stringWithFormat:@"0人正在关注"],@"",@"",@""];
  213. }
  214. }
  215. else
  216. {
  217. if ([dic[@"READNUM"] isEqualToString:@""])
  218. {
  219. arr = @[[NSString stringWithFormat:@"%@人参与话题",[self isWan:dic[@"COMMENTNUM"]]],[NSString stringWithFormat:@"0人正在关注"],@"",@"",@""];
  220. }
  221. }
  222. [details addObject:arr];
  223. NSString *xc = dic[@"TOPICNUM"];
  224. NSString *zb = dic[@"ZB"];
  225. NSString *wd = dic[@"WD"];
  226. if ([dic[@"TOPICNUM"] isEqualToString:@""]) {
  227. xc = @"0";
  228. }
  229. if ([dic[@"ZB"] isEqualToString:@""]) {
  230. zb = @"0";
  231. }
  232. if ([dic[@"WD"] isEqualToString:@""]) {
  233. wd = @"0";
  234. }
  235. arr = @[[NSString stringWithFormat:@"有%@人在学车",[self isWan:xc]],[NSString stringWithFormat:@"有%@人参与直播",[self isWan:zb]],[NSString stringWithFormat:@"有%@人参与问答",[self isWan:wd]],@"",@"",@""];
  236. [details addObject:arr];
  237. arr = @[@"",@"",@""];
  238. [details addObject:arr];
  239. [myTableView reloadData];
  240. }
  241. }];
  242. }
  243. //将超过四位的万位数 改写为x.x万
  244. -(NSString *)isWan:(NSString *)string
  245. {
  246. NSString *newString = string;
  247. if (string.length > 4) {
  248. newString = [NSString stringWithFormat:@"%@.%@万",[string substringToIndex:string.length - 4],[string substringWithRange:NSMakeRange(string.length - 4, 1)]];
  249. }
  250. //NSLog(@"newString---->%@",newString);
  251. return newString;
  252. }
  253. @end