#import "LearnDrivingVC.h" #import "MyUINavigationController.h" #import "CommunityVC.h" #import "DiaryVC.h" #import "CLCell.h" #import "LoginViewController.h" #import "TopicesVC.h" #import "NewsOfLearnVC.h" //#import "RecordOfLearnVC.h" #import "GuideVC.h" #import "CoachDetailInfoVC.h" #import "ShareVC.h" @interface LearnDrivingVC () { UITableView* myTableView; NSMutableArray* titles; NSMutableArray* images; NSMutableArray* details; NSMutableArray *countArray; } @end @implementation LearnDrivingVC - (void)viewDidLoad { [super viewDidLoad]; [self myInit]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated } -(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self getCurrentTopicTj]; } -(void)viewWillDisappear:(BOOL)animated{ [self setHidesBottomBarWhenPushed:NO]; [super viewWillDisappear:animated]; } #pragma mark - -(void)myInit { self.navigationItem.title = @"学车社区"; [self.view setBackgroundColor:backGroundColor]; countArray = [NSMutableArray alloc]; titles = [NSMutableArray array]; images = [NSMutableArray array]; details = [NSMutableArray array]; NSArray* arr; arr = @[@"驾考社区",@"驾考头条",@"学车指南"]; [titles addObject:arr]; arr = @[@"学车记录",@"学车问答",@"我的学车日记"];//@"学车直播", [titles addObject:arr]; arr = @[@"我的教练"]; [titles addObject:arr]; arr = @[@"learn_img01.png",@"learn_img02.png",@"learn_img03.png"]; [images addObject:arr]; arr = @[@"learn_img04.png",@"learn_img06.png"]; [images addObject:arr]; arr = @[@"learn_img07.png",@"learn_img08.png",@"learn_img09.png"]; [images addObject:arr]; arr = @[[NSString stringWithFormat:@"%d人参与讨论",arc4random()%100],[NSString stringWithFormat:@"%d万人正在关注",arc4random()%7],@"",@"",@""]; [details addObject:arr]; arr = @[[NSString stringWithFormat:@"有%d人在学车",arc4random()%100],[NSString stringWithFormat:@"有%d人参与问答",arc4random()%100],@"",@""];//,[NSString stringWithFormat:@"有%d人参与直播",arc4random()%100] [details addObject:arr]; arr = @[@"",@"",@""]; [details addObject:arr]; myTableView = [[UITableView alloc] initWithFrame:kFrame style:UITableViewStyleGrouped]; myTableView.height -= kTabBarHeight; [self.view addSubview:myTableView]; [myTableView setDelegate:self]; [myTableView setDataSource:self]; myTableView.estimatedSectionHeaderHeight = 0; myTableView.estimatedSectionFooterHeight = 0; } #pragma mark - -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return .1; } -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 10; } -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return titles.count; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { NSArray *array = titles[section]; return [array count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString* reuseID = @"learningCell"; UITableViewCell* cell; if (!cell) { cell = [[CLCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuseID]; [cell.detailTextLabel setFont:[UIFont scaleSize:13]]; [cell.textLabel setTextColor:contentTextColor]; [cell.textLabel setFont:[UIFont scaleSize:15]]; } [cell.textLabel setText:[titles objAtPath:indexPath] ]; if (indexPath.section == 1 && indexPath.row == 2) { [cell.textLabel setTextAlignment:NSTextAlignmentCenter]; [cell.textLabel setTextColor:contentTextColor]; return cell; } [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator]; UIImage* img = [UIImage imageNamed:[images objAtPath:indexPath] ]; [cell.imageView setImage:img]; [cell.detailTextLabel setText:[details objAtPath:indexPath] ]; return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; if (0 == indexPath.section) { if (0 == indexPath.row) { CommunityVC* vc = [[CommunityVC alloc] init]; [self navPushHideTabbarToVC:vc]; } if (1 == indexPath.row) { // ShareVC* vc = [[ShareVC alloc] init]; // [self navPushHideTabbarToVC:vc]; // 驾考头条 这里改为驾考新闻 直接进入新闻页面 NewsOfLearnVC* vc = [[NewsOfLearnVC alloc] init]; [self navPushHideTabbarToVC:vc]; } if (2 == indexPath.row) { GuideVC* vc = [[GuideVC alloc] init]; [self navPushHideTabbarToVC:vc]; } } if (1 == indexPath.section) { if (0 == indexPath.row) { // RecordOfLearnVC* vc = [[RecordOfLearnVC alloc] init]; TopicesVC* vc = [[TopicesVC alloc] init]; vc.type = @"2"; vc.groupId = @""; vc.childID = @""; [self navPushHideTabbarToVC:vc]; } // if (1 == indexPath.row) { // TopicesVC* vc = [[TopicesVC alloc] init]; // vc.type = @"3"; // [self navPushHideTabbarToVC:vc]; // } if (1 == indexPath.row) { TopicesVC* vc = [[TopicesVC alloc] init]; vc.type = @"4"; [self navPushHideTabbarToVC:vc]; } if (2 == indexPath.row) { if (!myDelegate.isLogin) { [LoginViewController loginFromVC:self]; return; } DiaryVC* vc = [[DiaryVC alloc] init]; vc.userID = defUser.userDict[@"id"]; [self navPushHideTabbarToVC:vc]; } } if (2 == indexPath.section) { if (myDelegate.isLogin) { CoachDetailInfoVC* vc = [[CoachDetailInfoVC alloc] init]; MyUINavigationController* nav = [[MyUINavigationController alloc] initWithRootViewController:vc]; nav.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; nav.modalPresentationStyle = UIModalPresentationFullScreen; [self.parentViewController presentViewController:nav animated:YES completion:nil]; }else{ ShowMsg(@"请登录后再操作!"); [LoginViewController loginFromVC:self]; } } } #pragma mark - /** */ -(void)getCurrentTopicTj { if (![Util connectedToNetWork]) { showMsgUnconnect(); return; } NSString* method = @"getCurrentTopicTj"; [jiaPeiManager requestGetAnythingWithURL:method completion:^(NSDictionary *dict) { //NSLog(@"getCurrentTopicTj%@",dict); if (!dict) { ShowMsgFailed(); return; } if ([dict[@"code"] isEqualToString:@"1"]) { ShowMsg(dict[@"body"]); return; } NSDictionary *dic = dict[@"body"]; if (dic && [[dic allKeys] count] > 0) { [details removeAllObjects]; NSArray *arr; arr = @[[NSString stringWithFormat:@"%@人参与话题",[self isWan:dic[@"COMMENTNUM"]]],[NSString stringWithFormat:@"%@人正在关注",[self isWan:dic[@"READNUM"]]],@"",@"",@""]; if ([dic[@"COMMENTNUM"] isEqualToString:@""]) { arr = @[[NSString stringWithFormat:@"0人参与话题"],[NSString stringWithFormat:@"%@人正在关注",[self isWan:dic[@"READNUM"]]],@"",@"",@""]; if ([dic[@"READNUM"] isEqualToString:@""]) { arr = @[[NSString stringWithFormat:@"0人参与话题"],[NSString stringWithFormat:@"0人正在关注"],@"",@"",@""]; } } else { if ([dic[@"READNUM"] isEqualToString:@""]) { arr = @[[NSString stringWithFormat:@"%@人参与话题",[self isWan:dic[@"COMMENTNUM"]]],[NSString stringWithFormat:@"0人正在关注"],@"",@"",@""]; } } [details addObject:arr]; NSString *xc = dic[@"TOPICNUM"]; NSString *zb = dic[@"ZB"]; NSString *wd = dic[@"WD"]; if ([dic[@"TOPICNUM"] isEqualToString:@""]) { xc = @"0"; } if ([dic[@"ZB"] isEqualToString:@""]) { zb = @"0"; } if ([dic[@"WD"] isEqualToString:@""]) { wd = @"0"; } arr = @[[NSString stringWithFormat:@"有%@人在学车",[self isWan:xc]],[NSString stringWithFormat:@"有%@人参与直播",[self isWan:zb]],[NSString stringWithFormat:@"有%@人参与问答",[self isWan:wd]],@"",@"",@""]; [details addObject:arr]; arr = @[@"",@"",@""]; [details addObject:arr]; [myTableView reloadData]; } }]; } //将超过四位的万位数 改写为x.x万 -(NSString *)isWan:(NSString *)string { NSString *newString = string; if (string.length > 4) { newString = [NSString stringWithFormat:@"%@.%@万",[string substringToIndex:string.length - 4],[string substringWithRange:NSMakeRange(string.length - 4, 1)]]; } //NSLog(@"newString---->%@",newString); return newString; } @end