// // JXExamViewController.m // shiku_im // // Created by qiudezheng on 2020/4/29. // Copyright © 2020 Reese. All rights reserved. // #import "JXExamViewController.h" #import "JXQuestionTableViewCell.h" #import "JXApplyViewController.h" @interface JXExamViewController () @property(strong,nonatomic)UIView * navigationView; @property(strong,nonatomic)UIView * alertViews; @property(strong,nonatomic)UILabel * alertLabel; @property(strong,nonatomic)UILabel * countLabel; @property(strong,nonatomic)UIButton * backButton; @property(strong,nonatomic)UILabel * questionLabel; @property(strong,nonatomic)UILabel * questionTitle; @property(strong,nonatomic)UITableView * questionTable; @property(strong,nonatomic)UIScrollView * scrollView; @property(strong,nonatomic)NSArray * questionArray; @property(assign,nonatomic)int currentSort; @property(strong,nonatomic)NSDictionary * currentQuestion; @property(strong,nonatomic)NSTimer * timer; @property(assign,nonatomic)int count; @property (nonatomic,assign) NSInteger indexRightRow; @end @implementation JXExamViewController -(void)viewWillDisappear:(BOOL)animated { [SVProgressHUD dismiss]; } - (void)viewDidLoad { [super viewDidLoad]; _currentQuestion=[NSDictionary dictionary]; self.view.backgroundColor = [UIColor colorWithRed:126/255.0f green:23/255.0f blue:21/255.0f alpha:1.0f]; self.tableView.alpha = 0.0f; self.currentSort = 1; [self initNavigationView]; [self initComponents]; [SVProgressHUD show]; self.count = 5; long time = (long)[[NSDate date] timeIntervalSince1970]; time = (time *1000 + g_server.timeDifference); NSString *salt = [NSString stringWithFormat:@"%ld", time]; [g_server getAllQuestions:salt andToView:self]; self.alertViews = [[UIView alloc]initWithFrame:CGRectMake(0,0,JX_SCREEN_WIDTH,JX_SCREEN_HEIGHT)]; self.alertViews.backgroundColor = [UIColor blackColor]; self.alertViews.alpha = 0.0f; [self.view addSubview:self.alertViews]; self.alertLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, JX_SCREEN_HEIGHT/ 2 - 50, self.alertViews.frame.size.width, 100)]; self.alertLabel.text = @"恭喜你答对了"; self.alertLabel.textColor = [UIColor whiteColor]; self.alertLabel.font = [UIFont systemFontOfSize:16.0f]; self.alertLabel.textAlignment = NSTextAlignmentCenter; self.alertLabel.numberOfLines = 2; [self.alertViews addSubview:self.alertLabel]; self.countLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, self.alertLabel.frame.size.height + self.alertLabel.frame.origin.y, self.alertViews.frame.size.width, 20)]; self.countLabel.text = @"5s"; self.countLabel.textColor = [UIColor whiteColor]; self.countLabel.font = [UIFont systemFontOfSize:14.0f]; self.countLabel.textAlignment = NSTextAlignmentCenter; [self.alertViews addSubview:self.countLabel]; if([self.ifAnswer isEqualToString:@"NO"]) { UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"您已完成今日答题" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil]; [alert show]; } } #pragma mark --- 提交 -(void)postButtonClicked:(UIButton *)sender { if([self.ifAnswer isEqualToString:@"NO"]) { [SVProgressHUD setMaximumDismissTimeInterval:2]; [SVProgressHUD showErrorWithStatus:@"已经完成所有答题"]; } else { NSMutableArray * mutableArray = [[NSMutableArray alloc]initWithCapacity:0]; for(NSDictionary * dict in self.questionArray) { NSString * lastAnswer = [NSString stringWithFormat:@"%@",[dict objectForKey:@"answerid"]]; if(lastAnswer != nil && lastAnswer.length != 0 && ![lastAnswer isEqualToString:@"(null)"] && ![lastAnswer isEqualToString:@""]) { NSDictionary * dictionary = [[NSDictionary alloc]initWithObjectsAndKeys:[NSString stringWithFormat:@"%@",[dict objectForKey:@"id"]],@"questionId",lastAnswer,@"optionId", nil]; [mutableArray addObject:dictionary]; long time = (long)[[NSDate date] timeIntervalSince1970]; time = (time *1000 + g_server.timeDifference); NSString *salt = [NSString stringWithFormat:@"%ld", time]; NSArray * postArray = mutableArray.copy; NSError *parseError = nil; NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postArray options:NSJSONWritingPrettyPrinted error:&parseError]; NSString *jsonstr =[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; [SVProgressHUD show]; [g_server postQuestionAnswers:salt andOptions:jsonstr andToView:self]; } else { UIAlertView * aler = [[UIAlertView alloc]initWithTitle:@"提示" message:[NSString stringWithFormat:@"您有题目没有答完,请返回检查"] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil]; [aler show]; break; } } } } -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{ // [_wait hide]; [SVProgressHUD dismiss]; if([aDownload.action isEqualToString:act_GetQuestionAndRules]) { NSDictionary * dictionary0 = [array1 objectAtIndex:0]; self.questionArray = [dictionary0 objectForKey:@"questions"]; if(self.questionArray.count == 0) { self.questionTable.alpha = 0.0f; } else { for(NSDictionary * dictionary in self.questionArray) { NSString * questionSort = [NSString stringWithFormat:@"%@",[dictionary objectForKey:@"sort"]]; if(questionSort.intValue == 1) { NSString * questionTitle = [NSString stringWithFormat:@"第%@题:%@",questionSort,[dictionary objectForKey:@"title"]]; NSString * questionDesc = [NSString stringWithFormat:@"%@",[dictionary objectForKey:@"desc"]]; if(questionTitle != nil && questionTitle.length != 0 && ![questionTitle isEqualToString:@"(null)"] && ![questionTitle isEqualToString:@""]) { self.questionTitle.text = questionTitle; } if(questionDesc != nil && questionDesc.length != 0 && ![questionDesc isEqualToString:@"(null)"] && ![questionDesc isEqualToString:@""]) { self.questionLabel.text = questionDesc; } self.currentQuestion = dictionary; break; } } [self.questionTable reloadData]; } } if([aDownload.action isEqualToString:act_PostQuestionAnswers]) { NSString * rightCount = [NSString stringWithFormat:@"%@",[dict objectForKey:@"rightCount"]]; NSString * coinCount = [NSString stringWithFormat:@"%@",[dict objectForKey:@"coinCount"]]; UIAlertView * alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:[NSString stringWithFormat:@"您一共答对了%@道题,获得金币%@",rightCount,coinCount] delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil]; alertView.tag = 1000; [alertView show]; [[NSNotificationCenter defaultCenter]postNotificationName:@"refreshes" object:nil]; } } -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{ NSString * errorCode = [NSString stringWithFormat:@"%@",[dict objectForKey:@"resultMsg"]]; if([errorCode isEqualToString:@"权限验证失败"]) { if([aDownload.action isEqualToString:act_GetQuestionAndRules]) { long time = (long)[[NSDate date] timeIntervalSince1970]; time = (time *1000 + g_server.timeDifference); NSString *salt = [NSString stringWithFormat:@"%ld", time]; [g_server getAllQuestions:salt andToView:self]; } if([aDownload.action isEqualToString:act_PostQuestionAnswers]) { if([self.ifAnswer isEqualToString:@"NO"]) { [SVProgressHUD setMaximumDismissTimeInterval:2]; [SVProgressHUD showErrorWithStatus:@"已经完成所有答题"]; } else { NSMutableArray * mutableArray = [[NSMutableArray alloc]initWithCapacity:0]; for(NSDictionary * dict in self.questionArray) { NSString * lastAnswer = [NSString stringWithFormat:@"%@",[dict objectForKey:@"answerid"]]; if(lastAnswer != nil && lastAnswer.length != 0 && ![lastAnswer isEqualToString:@"(null)"] && ![lastAnswer isEqualToString:@""]) { NSDictionary * dictionary = [[NSDictionary alloc]initWithObjectsAndKeys:[NSString stringWithFormat:@"%@",[dict objectForKey:@"id"]],@"questionId",lastAnswer,@"optionId", nil]; [mutableArray addObject:dictionary]; } else { UIAlertView * aler = [[UIAlertView alloc]initWithTitle:@"提示" message:[NSString stringWithFormat:@"您有题目没有答完,请返回检查"] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil]; [aler show]; break; } } long time = (long)[[NSDate date] timeIntervalSince1970]; time = (time *1000 + g_server.timeDifference); NSString *salt = [NSString stringWithFormat:@"%ld", time]; NSArray * postArray = mutableArray.copy; NSError *parseError = nil; NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postArray options:NSJSONWritingPrettyPrinted error:&parseError]; NSString *jsonstr =[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; [g_server postQuestionAnswers:salt andOptions:jsonstr andToView:self]; } } } else { [SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"%@",[dict objectForKey:@"resultMsg"]]]; } if( [aDownload.action isEqualToString:act_UserLogout] ){ [self performSelector:@selector(doSwitch) withObject:nil afterDelay:1]; } return hide_error; } -(void)backButtonClicked:(UIButton *)sender { [g_navigation dismissViewController:self animated:YES]; } -(void)initNavigationView { self.navigationView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT>=812?88:64)]; self.navigationView.backgroundColor = [UIColor whiteColor]; [self.view addSubview:self.navigationView]; UILabel * titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, JX_SCREEN_TOP - 40, JX_SCREEN_WIDTH, 40)]; titleLabel.text = @"每日答题"; titleLabel.textColor = [UIColor blackColor]; titleLabel.font = [UIFont systemFontOfSize:18.0f]; titleLabel.textAlignment = NSTextAlignmentCenter; [self.navigationView addSubview:titleLabel]; self.backButton = [UIButton buttonWithType:UIButtonTypeCustom]; self.backButton.frame = CGRectMake(15, 30, 30, 30); if(JX_SCREEN_HEIGHT >= 812) { self.backButton.frame = CGRectMake(15, 45, 30, 30); } [self.backButton setImage:[UIImage imageNamed:@"title_back_black"] forState:UIControlStateNormal]; [self.backButton addTarget:self action:@selector(backButtonClicked:) forControlEvents:UIControlEventTouchUpInside]; [self.navigationView addSubview:self.backButton]; } -(void)initComponents { self.scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, self.navigationView.frame.origin.y + self.navigationView.frame.size.height, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT - (self.navigationView.frame.origin.y + self.navigationView.frame.size.height))]; self.scrollView.backgroundColor = self.view.backgroundColor; self.scrollView.contentSize = CGSizeMake(JX_SCREEN_WIDTH, self.scrollView.frame.size.height); [self.view addSubview:self.scrollView]; UIImageView * backView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, 0.68*JX_SCREEN_WIDTH)]; backView.image = [UIImage imageNamed:@"questionBacks"]; [self.scrollView addSubview:backView]; backView.userInteractionEnabled = YES; UIButton * postButton = [UIButton buttonWithType:UIButtonTypeCustom]; postButton.frame = CGRectMake(JX_SCREEN_WIDTH - 70 - 15, backView.frame.size.height - 30, 70, 30); [postButton setBackgroundColor:[UIColor colorWithRed:253/255.0f green:219/255.0f blue:173/255.0f alpha:1.0f]]; [postButton setTitle:@"提交" forState:UIControlStateNormal]; [postButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [postButton.titleLabel setFont:[UIFont systemFontOfSize:13.0f]]; [postButton.layer setCornerRadius:5.0f]; [postButton.layer setMasksToBounds:YES]; [postButton addTarget:self action:@selector(postButtonClicked:) forControlEvents:UIControlEventTouchUpInside]; [backView addSubview:postButton]; // if(!self.ifAnswer.boolValue) // { // postButton.userInteractionEnabled = NO; // } // else // { // postButton.userInteractionEnabled = YES; // } UIImageView * questionView = [[UIImageView alloc]initWithFrame:CGRectMake(10, backView.frame.origin.y + backView.frame.size.height + 15, JX_SCREEN_WIDTH - 20, 0.84*(JX_SCREEN_WIDTH-20-40))]; questionView.image = [UIImage imageNamed:@"questionImage"]; [self.scrollView addSubview:questionView]; questionView.userInteractionEnabled = YES; self.questionTitle = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, questionView.frame.size.width, 40)]; self.questionTitle.text = @""; self.questionTitle.textColor = [UIColor colorWithRed:115/255.0f green:20/255.0f blue:5/255.0f alpha:1.0f]; self.questionTitle.font = [UIFont boldSystemFontOfSize:15.0f]; self.questionTitle.textAlignment = NSTextAlignmentCenter; [questionView addSubview:self.questionTitle]; self.questionLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 40, questionView.frame.size.width - 30, 40)]; self.questionLabel.text = @""; self.questionLabel.textColor = self.questionTitle.textColor; self.questionLabel.font = [UIFont systemFontOfSize:15.0f]; [questionView addSubview:self.questionLabel]; self.questionTable = [[UITableView alloc]initWithFrame:CGRectMake(0, self.questionLabel.frame.origin.y + self.questionLabel.frame.size.height, questionView.frame.size.width, questionView.frame.size.height - (self.questionLabel.frame.origin.y + self.questionLabel.frame.size.height)) style:UITableViewStylePlain]; self.questionTable.dataSource = self; self.questionTable.delegate = self; self.questionTable.separatorStyle = UITableViewCellSeparatorStyleNone; self.questionTable.backgroundColor = [UIColor clearColor]; [questionView addSubview:self.questionTable]; if([self.ifAnswer isEqualToString:@"NO"]) { self.questionTable.userInteractionEnabled = NO; } else { self.questionTable.userInteractionEnabled = YES; } UIButton * preButton = [UIButton buttonWithType:UIButtonTypeCustom]; preButton.frame = CGRectMake(JX_SCREEN_WIDTH/2 - 80 - 50, questionView.frame.origin.y + questionView.frame.size.height + 15, 80, 30); [preButton setBackgroundColor:[UIColor colorWithRed:253/255.0f green:219/255.0f blue:173/255.0f alpha:1.0f]]; [preButton setTitle:@"上一题" forState:UIControlStateNormal]; [preButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [preButton.titleLabel setFont:[UIFont systemFontOfSize:13.0f]]; [preButton.layer setCornerRadius:5.0f]; [preButton.layer setMasksToBounds:YES]; [preButton addTarget:self action:@selector(preButtonClicked:) forControlEvents:UIControlEventTouchUpInside]; preButton.alpha =1.0f; [self.scrollView addSubview:preButton]; UIButton * nextButton = [UIButton buttonWithType:UIButtonTypeCustom]; nextButton.frame = CGRectMake(JX_SCREEN_WIDTH/2 + 50, preButton.frame.origin.y, 80, 30); [nextButton setBackgroundColor:[UIColor colorWithRed:253/255.0f green:219/255.0f blue:173/255.0f alpha:1.0f]]; [nextButton setTitle:@"下一题" forState:UIControlStateNormal]; [nextButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [nextButton.titleLabel setFont:[UIFont systemFontOfSize:13.0f]]; [nextButton.layer setCornerRadius:5.0f]; [nextButton.layer setMasksToBounds:YES]; [nextButton addTarget:self action:@selector(nextButtonClicked:) forControlEvents:UIControlEventTouchUpInside]; nextButton.alpha = 1.0f; [self.scrollView addSubview:nextButton]; self.scrollView.contentSize = CGSizeMake(JX_SCREEN_WIDTH, preButton.frame.origin.y + preButton.frame.size.height + 20); } -(void)nextButtonClicked:(UIButton *)sender { self.currentSort ++; BOOL check = NO; for(NSDictionary * dictionary in self.questionArray) { NSString * questionSort = [NSString stringWithFormat:@"%@",[dictionary objectForKey:@"sort"]]; if(questionSort.intValue == self.currentSort) { NSString * questionTitle = [NSString stringWithFormat:@"第%@题:%@",questionSort,[dictionary objectForKey:@"title"]]; NSString * questionDesc = [NSString stringWithFormat:@"%@",[dictionary objectForKey:@"desc"]]; if(questionTitle != nil && questionTitle.length != 0 && ![questionTitle isEqualToString:@"(null)"] && ![questionTitle isEqualToString:@""]) { self.questionTitle.text = questionTitle; } if(questionDesc != nil && questionDesc.length != 0 && ![questionDesc isEqualToString:@"(null)"] && ![questionDesc isEqualToString:@""]) { self.questionLabel.text = questionDesc; } self.currentQuestion = dictionary; check = YES; break; } } if(!check) { UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"当前已是最后一题了" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil]; [alert show]; self.currentSort --; } else { [self.questionTable reloadData]; } } -(void)preButtonClicked:(UIButton *)sender { if(self.currentSort > 1) { self.currentSort --; for(NSDictionary * dictionary in self.questionArray) { NSString * questionSort = [NSString stringWithFormat:@"%@",[dictionary objectForKey:@"sort"]]; if(questionSort.intValue == self.currentSort) { NSString * questionTitle = [NSString stringWithFormat:@"第%@题:%@",questionSort,[dictionary objectForKey:@"title"]]; NSString * questionDesc = [NSString stringWithFormat:@"%@",[dictionary objectForKey:@"desc"]]; if(questionTitle != nil && questionTitle.length != 0 && ![questionTitle isEqualToString:@"(null)"] && ![questionTitle isEqualToString:@""]) { self.questionTitle.text = questionTitle; } if(questionDesc != nil && questionDesc.length != 0 && ![questionDesc isEqualToString:@"(null)"] && ![questionDesc isEqualToString:@""]) { self.questionLabel.text = questionDesc; } self.currentQuestion = dictionary; break; } } [self.questionTable reloadData]; } else { UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"当前是第一题了" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil]; [alert show]; } } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { NSArray * options = [self.currentQuestion objectForKey:@"options"]; return options.count; } #pragma mark --- 代理 tableView -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { JXQuestionTableViewCell * cell = [JXQuestionTableViewCell cellWithTableView:tableView]; NSArray * options = [_currentQuestion objectForKey:@"options"]; NSDictionary * dictionary = [options objectAtIndex:[indexPath row]]; NSString * lastAnswer = [NSString stringWithFormat:@"%@",[_currentQuestion objectForKey:@"answerid"]]; if(lastAnswer != nil && lastAnswer.length != 0 && ![lastAnswer isEqualToString:@"(null)"] && ![lastAnswer isEqualToString:@""]) { NSString * currentAnswerID = [NSString stringWithFormat:@"%@",[dictionary objectForKey:@"id"]]; if(currentAnswerID.intValue == lastAnswer.intValue) { NSString * ifRight = [NSString stringWithFormat:@"%@",[dictionary objectForKey:@"right"]]; if(ifRight.boolValue) { if (_indexRightRow==indexPath.row) { cell.correctImage.alpha = 1.0f; cell.greenGouIMG.alpha=1.0; }else{ cell.correctImage.alpha = 1.0f; cell.greenGouIMG.alpha=1.0; } }else{ cell.wrongImage.alpha =1.0f; cell.redGouIMG.alpha=1.0; [options enumerateObjectsUsingBlock:^(NSDictionary *_Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { NSLog(@"right:--%@",obj[@"right"]); if ([obj[@"right"] intValue]==1) { *stop=YES; _indexRightRow=idx; NSIndexPath *indexPath=[NSIndexPath indexPathForRow:idx inSection:0]; [_questionTable reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft]; }else{ cell.correctImage.alpha = 0.0f; cell.greenGouIMG.alpha=0.0; } }]; } }else{ } cell.userInteractionEnabled = NO; } else { cell.correctImage.alpha = 0.0f; cell.greenGouIMG.alpha=0.0; cell.wrongImage.alpha =0.0f; cell.redGouIMG.alpha=0.0; cell.userInteractionEnabled = YES; } CGFloat ansWidth=[self ZFYtextHeightFromTextString:[dictionary objectForKey:@"title"] width:300 fontSize:15].width; cell.answerLabel.text = [NSString stringWithFormat:@"%@",[dictionary objectForKey:@"title"]]; cell.answerLabel.frame=CGRectMake(CGRectGetMaxX(cell.boxImage.frame)+15,0, ansWidth, 30); cell.wrongImage.frame=CGRectMake(CGRectGetMaxX(cell.answerLabel.frame)+15, 5, 20, 20); cell.correctImage.frame=CGRectMake(CGRectGetMaxX(cell.answerLabel.frame)+15, 5, 20, 20); cell.backgroundColor = [UIColor clearColor]; cell.answerLabel.text = [NSString stringWithFormat:@"%@",[dictionary objectForKey:@"title"]]; cell.backgroundColor = [UIColor clearColor]; cell.selectionStyle = UITableViewCellSelectionStyleNone; return cell; } -(CGSize)ZFYtextHeightFromTextString:(NSString *)text width:(CGFloat)textWidth fontSize:(CGFloat)size{ //计算 label需要的宽度和高度 NSDictionary *dict = @{NSFontAttributeName:[UIFont systemFontOfSize:size]}; CGSize size2 = [text boundingRectWithSize:CGSizeMake(textWidth, MAXFLOAT) options:NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesFontLeading|NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil].size; //CGSize size1 = [text sizeWithAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:size]}]; return size2; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 40.0f; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSArray * options = [self.currentQuestion objectForKey:@"options"]; NSDictionary * dictionary = [options objectAtIndex:[indexPath row]]; NSString * answerID = [NSString stringWithFormat:@"%@",[dictionary objectForKey:@"id"]]; NSMutableDictionary * mutableDic = self.currentQuestion.mutableCopy; [mutableDic setObject:answerID forKey:@"answerid"]; self.currentQuestion = mutableDic.copy; //sort 代表第几题 NSString * sort = [NSString stringWithFormat:@"%@",[self.currentQuestion objectForKey:@"sort"]]; NSMutableArray * mutableArray = self.questionArray.mutableCopy; for(int i=0;i<=(self.questionArray.count - 1);i++) { NSDictionary * dict = [self.questionArray objectAtIndex:i]; NSString * realSortID = [NSString stringWithFormat:@"%@",[dict objectForKey:@"sort"]]; if(sort.intValue == realSortID.intValue) { [mutableArray replaceObjectAtIndex:i withObject:self.currentQuestion]; break; } } self.questionArray = mutableArray; [_questionTable reloadData]; NSString * ifRight = [NSString stringWithFormat:@"%@",[dictionary objectForKey:@"right"]]; //return; if(ifRight.boolValue) { return; // self.alertLabel.text = @"恭喜你回答正确"; if(self.currentSort != self.questionArray.count) { self.currentSort ++; for(NSDictionary * dictionary in self.questionArray) { NSString * questionSort = [NSString stringWithFormat:@"%@",[dictionary objectForKey:@"sort"]]; if(questionSort.intValue == self.currentSort) { NSString * questionTitle = [NSString stringWithFormat:@"第%@题:%@",questionSort,[dictionary objectForKey:@"title"]]; NSString * questionDesc = [NSString stringWithFormat:@"%@",[dictionary objectForKey:@"desc"]]; if(questionTitle != nil && questionTitle.length != 0 && ![questionTitle isEqualToString:@"(null)"] && ![questionTitle isEqualToString:@""]) { self.questionTitle.text = questionTitle; } if(questionDesc != nil && questionDesc.length != 0 && ![questionDesc isEqualToString:@"(null)"] && ![questionDesc isEqualToString:@""]) { self.questionLabel.text = questionDesc; } self.currentQuestion = dictionary; break; } } //[self.questionTable reloadData]; } } else { return;; //self.alertLabel.text = [NSString stringWithFormat:@"回答错误,正确答案是:%@",correctAnswer]; if(self.currentSort != self.questionArray.count) { self.currentSort ++; for(NSDictionary * dictionary in self.questionArray) { NSString * questionSort = [NSString stringWithFormat:@"%@",[dictionary objectForKey:@"sort"]]; if(questionSort.intValue == self.currentSort) { NSString * questionTitle = [NSString stringWithFormat:@"第%@题:%@",questionSort,[dictionary objectForKey:@"title"]]; NSString * questionDesc = [NSString stringWithFormat:@"%@",[dictionary objectForKey:@"desc"]]; if(questionTitle != nil && questionTitle.length != 0 && ![questionTitle isEqualToString:@"(null)"] && ![questionTitle isEqualToString:@""]) { self.questionTitle.text = questionTitle; } if(questionDesc != nil && questionDesc.length != 0 && ![questionDesc isEqualToString:@"(null)"] && ![questionDesc isEqualToString:@""]) { self.questionLabel.text = questionDesc; } self.currentQuestion = dictionary; break; } } // [self.questionTable reloadData]; } } } -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { if(alertView.tag == 1000) { [g_navigation popToViewController:[JXApplyViewController class] animated:YES]; } else if(alertView.tag == 10000) { self.currentSort ++; for(NSDictionary * dictionary in self.questionArray) { NSString * questionSort = [NSString stringWithFormat:@"%@",[dictionary objectForKey:@"sort"]]; if(questionSort.intValue == self.currentSort) { NSString * questionTitle = [NSString stringWithFormat:@"第%@题:%@",questionSort,[dictionary objectForKey:@"title"]]; NSString * questionDesc = [NSString stringWithFormat:@"%@",[dictionary objectForKey:@"desc"]]; if(questionTitle != nil && questionTitle.length != 0 && ![questionTitle isEqualToString:@"(null)"] && ![questionTitle isEqualToString:@""]) { self.questionTitle.text = questionTitle; } if(questionDesc != nil && questionDesc.length != 0 && ![questionDesc isEqualToString:@"(null)"] && ![questionDesc isEqualToString:@""]) { self.questionLabel.text = questionDesc; } self.currentQuestion = dictionary; break; } } [self.questionTable reloadData]; } } @end