JXQuestionnVc.m 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. //
  2. // JXExamViewController.m
  3. // shiku_im
  4. //
  5. // Created by qiudezheng on 2020/4/29.
  6. // Copyright © 2020 Reese. All rights reserved.
  7. //
  8. #import "JXQuestionnVc.h"
  9. #import "JXQuestionCell.h"
  10. #import "JXApplyViewController.h"
  11. @interface JXQuestionnVc ()<UIAlertViewDelegate>
  12. @property(strong,nonatomic)UIView * navigationView;
  13. @property(strong,nonatomic)UIView * alertViews;
  14. @property(strong,nonatomic)UILabel * alertLabel;
  15. @property(strong,nonatomic)UILabel * countLabel;
  16. @property(strong,nonatomic)UIButton * backButton;
  17. @property(strong,nonatomic)UILabel * questionLabel;
  18. @property(strong,nonatomic)UILabel * questionTitle;
  19. @property(strong,nonatomic)UITableView * questionTable;
  20. @property(strong,nonatomic)UIScrollView * scrollView;
  21. @property(strong,nonatomic)NSArray * questionArray;
  22. @property(assign,nonatomic)NSUInteger currentSort;
  23. @property(strong,nonatomic)NSDictionary * currentQuestion;
  24. @property(strong,nonatomic)NSTimer * timer;
  25. @property(assign,nonatomic)int count;
  26. @property (nonatomic,assign) NSInteger indexRightRow;
  27. @property (nonatomic,strong) NSMutableArray *dataArr;
  28. @property (nonatomic,strong) NSMutableArray *firstArr;
  29. @property (nonatomic,strong) NSMutableArray *questionArr;
  30. @property (nonatomic,strong) NSMutableArray *ruleArr;
  31. @property (nonatomic,assign) NSInteger indexRecordIndex;
  32. @property (nonatomic,assign) NSInteger indexRow;
  33. @property (nonatomic,strong) NSMutableArray *saveSelectIndexArr;
  34. @property (nonatomic,strong) NSMutableDictionary *saveSelectIndexDict;
  35. @property (nonatomic,weak) UIAlertView * aler;
  36. @property (nonatomic,strong) NSMutableArray *dataArr222;
  37. @property (nonatomic,strong) NSMutableArray *dataArr333;
  38. @end
  39. @implementation JXQuestionnVc
  40. -(void)viewWillDisappear:(BOOL)animated
  41. {
  42. [SVProgressHUD dismiss];
  43. }
  44. - (void)viewDidLoad {
  45. [super viewDidLoad];
  46. _currentQuestion=[NSDictionary dictionary];
  47. _indexRightRow=100;
  48. _indexRow=200;
  49. //保存选中的数据
  50. _saveSelectIndexArr=[NSMutableArray array];
  51. _saveSelectIndexDict=[NSMutableDictionary dictionary];
  52. _firstArr=[NSMutableArray array];
  53. _dataArr222=[NSMutableArray array];
  54. _dataArr333=[NSMutableArray array];
  55. _dataArr=[NSMutableArray array];
  56. _questionArr=[NSMutableArray array];
  57. _ruleArr=[NSMutableArray array];
  58. self.view.backgroundColor = [UIColor colorWithRed:126/255.0f green:23/255.0f blue:21/255.0f alpha:1.0f];
  59. self.tableView.alpha = 0.0f;
  60. self.currentSort = 0;
  61. [self initNavigationView];
  62. [self initComponents];
  63. [SVProgressHUD show];
  64. self.count = 5;
  65. long time = (long)[[NSDate date] timeIntervalSince1970];
  66. time = (time *1000 + g_server.timeDifference);
  67. NSString *salt = [NSString stringWithFormat:@"%ld", time];
  68. [g_server getAllQuestions:salt andToView:self];
  69. if([self.ifAnswer isEqualToString:@"NO"])
  70. {
  71. UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"您已完成今日答题" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
  72. [alert show];
  73. }
  74. }
  75. #pragma mark --- 提交
  76. -(void)postButtonClicked:(UIButton *)sender
  77. {
  78. //_saveSelectIndexArr;
  79. if (_dataArr333.count==10) {
  80. [SVProgressHUD setMaximumDismissTimeInterval:2];
  81. [SVProgressHUD showErrorWithStatus:@"已经完成所有答题"];
  82. NSMutableArray * mutableArray = [[NSMutableArray alloc]initWithCapacity:0];
  83. [_dataArr333 enumerateObjectsUsingBlock:^(QustionJX * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  84. NSDictionary * dictionary = @{@"questionId":[NSString stringWithFormat:@"%@",obj.id],@"optionId":@"1"};
  85. [mutableArray addObject:dictionary];
  86. }];
  87. long time = (long)[[NSDate date] timeIntervalSince1970];
  88. time = (time *1000 + g_server.timeDifference);
  89. NSString *salt = [NSString stringWithFormat:@"%ld", time];
  90. NSArray * postArray = mutableArray.copy;
  91. NSError *parseError = nil;
  92. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postArray options:NSJSONWritingPrettyPrinted error:&parseError];
  93. NSString *jsonstr =[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
  94. [SVProgressHUD show];
  95. [g_server postQuestionAnswers:salt andOptions:jsonstr andToView:self];
  96. }else{
  97. UIAlertView * aler = [[UIAlertView alloc]initWithTitle:@"提示" message:[NSString stringWithFormat:@"您有题目没有答完,请返回检查"] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
  98. [aler show];
  99. self.aler=aler;
  100. }
  101. if([self.ifAnswer isEqualToString:@"NO"])
  102. {
  103. [SVProgressHUD setMaximumDismissTimeInterval:2];
  104. [SVProgressHUD showErrorWithStatus:@"已经完成所有答题"];
  105. }
  106. else
  107. {
  108. NSMutableArray * mutableArray = [[NSMutableArray alloc]initWithCapacity:0];
  109. for(NSDictionary * dict in _questionArray)
  110. {
  111. NSString * lastAnswer = [NSString stringWithFormat:@"%@",[dict objectForKey:@"answerid"]];
  112. if(lastAnswer != nil && lastAnswer.length != 0 && ![lastAnswer isEqualToString:@"(null)"] && ![lastAnswer isEqualToString:@"<null>"])
  113. {
  114. NSDictionary * dictionary = [[NSDictionary alloc]initWithObjectsAndKeys:[NSString stringWithFormat:@"%@",[dict objectForKey:@"id"]],@"questionId",lastAnswer,@"optionId", nil];
  115. [mutableArray addObject:dictionary];
  116. long time = (long)[[NSDate date] timeIntervalSince1970];
  117. time = (time *1000 + g_server.timeDifference);
  118. NSString *salt = [NSString stringWithFormat:@"%ld", time];
  119. NSArray * postArray = mutableArray.copy;
  120. NSError *parseError = nil;
  121. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postArray options:NSJSONWritingPrettyPrinted error:&parseError];
  122. NSString *jsonstr =[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
  123. [SVProgressHUD show];
  124. [g_server postQuestionAnswers:salt andOptions:jsonstr andToView:self];
  125. }
  126. else
  127. {
  128. UIAlertView * aler = [[UIAlertView alloc]initWithTitle:@"提示" message:[NSString stringWithFormat:@"您有题目没有答完,请返回检查"] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
  129. [aler show];
  130. self.aler=aler;
  131. break;
  132. }
  133. }
  134. }
  135. }
  136. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  137. return _dataArr.count;
  138. }
  139. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  140. {
  141. NSArray * options = [_currentQuestion objectForKey:@"options"];
  142. if (_firstArr.count==0) {
  143. return 0;
  144. }else{
  145. QustionJX *optionArr = _firstArr[section];
  146. return optionArr.options.count;
  147. }
  148. }
  149. #pragma mark --- 代理 tableView
  150. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  151. { //NSArray * options = [_currentQuestion objectForKey:@"options"];
  152. JXQuestionCell * cell = [JXQuestionCell cellWithTableView:tableView];
  153. QustionJX *optionArr = [_firstArr firstObject];
  154. OptionsJX *model=optionArr.options[indexPath.row];
  155. [cell createUI:model andDui:_indexRightRow andSelect:_indexRow andCell:indexPath.row];
  156. NSArray * options = [_currentQuestion objectForKey:@"options"];
  157. NSDictionary * dictionary = [options objectAtIndex:[indexPath row]];
  158. NSString * lastAnswer = [NSString stringWithFormat:@"%@",[_currentQuestion objectForKey:@"answerid"]];
  159. if(lastAnswer != nil && lastAnswer.length != 0 && ![lastAnswer isEqualToString:@"(null)"] && ![lastAnswer isEqualToString:@"<null>"])
  160. {
  161. NSString * currentAnswerID = [NSString stringWithFormat:@"%@",[dictionary objectForKey:@"id"]];
  162. if(currentAnswerID.intValue == lastAnswer.intValue)
  163. {
  164. NSString * ifRight = [NSString stringWithFormat:@"%@",[dictionary objectForKey:@"right"]];
  165. if(ifRight.boolValue)
  166. {
  167. }
  168. }
  169. cell.userInteractionEnabled = NO;
  170. }
  171. else
  172. {
  173. cell.userInteractionEnabled = YES;
  174. }
  175. return cell;
  176. }
  177. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  178. {
  179. return 40.0f;
  180. }
  181. #pragma mark --- 代理。did
  182. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  183. {
  184. QustionJX *optionArr = [_firstArr firstObject];
  185. __block OptionsJX *model=nil;
  186. _indexRow=indexPath.row;
  187. [optionArr.options enumerateObjectsUsingBlock:^(OptionsJX *_Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  188. if ( [obj.right isEqualToString:@"1"]) {
  189. _indexRightRow=idx;
  190. model=obj;
  191. *stop=YES;
  192. }
  193. }];
  194. __block QustionJX *modelS=nil;
  195. [_questionArr enumerateObjectsUsingBlock:^(QustionJX * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  196. // if ([obj.sort intValue]==_currentSort) {
  197. if ([obj.title isEqualToString:self.questionTitle.text]) {
  198. modelS=obj;
  199. }
  200. }];
  201. [_saveSelectIndexArr enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  202. QustionJX *modeljx=obj[@"option"];
  203. if ([modeljx.title isEqualToString:modelS.title] && [obj[@"checkNo"] intValue]==1) {
  204. self.questionTable.userInteractionEnabled=NO;
  205. _isclick=YES;
  206. *stop=YES;
  207. }else{
  208. _isclick=NO;
  209. self.questionTable.userInteractionEnabled=YES;
  210. }
  211. }];
  212. if (_isclick==YES) {
  213. return;
  214. }
  215. _isCheck=1;
  216. NSDictionary *dict=@{@"option":modelS,@"title":modelS.title,@"selectIndex":[NSString stringWithFormat:@"%zd",indexPath.row] ,@"rightRow":[NSString stringWithFormat:@"%zd",_indexRightRow],@"checkNo":[NSString stringWithFormat:@"%d",_isCheck],@"currentSort":[NSString stringWithFormat:@"%lu",(unsigned long)_currentSort]};
  217. [_saveSelectIndexArr addObject:dict];
  218. self.questionTitle.text = modelS.title ;
  219. [_dataArr333 addObject:modelS];
  220. if (_indexRightRow==indexPath.row) {
  221. [_dataArr222 addObject:modelS];
  222. }
  223. [_questionTable reloadData];
  224. }
  225. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  226. // [_wait hide];
  227. [SVProgressHUD dismiss];
  228. if([aDownload.action isEqualToString:act_GetQuestionAndRules])
  229. {
  230. NSDictionary * dict0 = [array1 objectAtIndex:0];
  231. NSLog(@"aaa %@",dict0);
  232. _questionArr=[QustionJX mj_objectArrayWithKeyValuesArray:dict0[@"questions"]];
  233. _ruleArr=[RulesJX mj_objectArrayWithKeyValuesArray:dict0[@"rules"]];
  234. [_firstArr addObject:[_questionArr firstObject]];
  235. /* [_questionArr enumerateObjectsUsingBlock:^(QustionJX * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  236. if (idx==0) {
  237. [_firstArr addObject:obj];
  238. }
  239. }];*/
  240. _dataArr=[packageRoolModel mj_objectArrayWithKeyValuesArray:array1];
  241. QustionJX *modell=[_firstArr firstObject];
  242. self.questionTitle.text = modell.title;
  243. [self.questionTable reloadData];
  244. [[NSNotificationCenter defaultCenter]postNotificationName:@"refreshes" object:nil];
  245. }if([aDownload.action isEqualToString:act_PostQuestionAnswers])
  246. {
  247. UIAlertView * aler = [[UIAlertView alloc]initWithTitle:@"提示" message:[NSString stringWithFormat:@"您答对了%zd",_dataArr222.count] delegate:self cancelButtonTitle:@"知道了" otherButtonTitles:nil];
  248. aler.tag=3000;
  249. [aler show];
  250. }
  251. }
  252. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  253. NSString * errorCode = [NSString stringWithFormat:@"%@",[dict objectForKey:@"resultMsg"]];
  254. if([errorCode isEqualToString:@"权限验证失败"])
  255. {
  256. if([aDownload.action isEqualToString:act_GetQuestionAndRules])
  257. {
  258. long time = (long)[[NSDate date] timeIntervalSince1970];
  259. time = (time *1000 + g_server.timeDifference);
  260. NSString *salt = [NSString stringWithFormat:@"%ld", time];
  261. [g_server getAllQuestions:salt andToView:self];
  262. }
  263. if([aDownload.action isEqualToString:act_PostQuestionAnswers])
  264. {
  265. if([self.ifAnswer isEqualToString:@"NO"])
  266. {
  267. [SVProgressHUD setMaximumDismissTimeInterval:2];
  268. [SVProgressHUD showErrorWithStatus:@"已经完成所有答题"];
  269. }
  270. else
  271. {
  272. NSMutableArray * mutableArray = [[NSMutableArray alloc]initWithCapacity:0];
  273. for(NSDictionary * dict in self.questionArray)
  274. {
  275. NSString * lastAnswer = [NSString stringWithFormat:@"%@",[dict objectForKey:@"answerid"]];
  276. if(lastAnswer != nil && lastAnswer.length != 0 && ![lastAnswer isEqualToString:@"(null)"] && ![lastAnswer isEqualToString:@"<null>"])
  277. {
  278. NSDictionary * dictionary = [[NSDictionary alloc]initWithObjectsAndKeys:[NSString stringWithFormat:@"%@",[dict objectForKey:@"id"]],@"questionId",lastAnswer,@"optionId", nil];
  279. [mutableArray addObject:dictionary];
  280. }
  281. else
  282. {
  283. UIAlertView * aler = [[UIAlertView alloc]initWithTitle:@"提示" message:[NSString stringWithFormat:@"您有题目没有答完,请返回检查"] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
  284. [aler show];
  285. break;
  286. }
  287. }
  288. long time = (long)[[NSDate date] timeIntervalSince1970];
  289. time = (time *1000 + g_server.timeDifference);
  290. NSString *salt = [NSString stringWithFormat:@"%ld", time];
  291. NSArray * postArray = mutableArray.copy;
  292. NSError *parseError = nil;
  293. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postArray options:NSJSONWritingPrettyPrinted error:&parseError];
  294. NSString *jsonstr =[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
  295. [g_server postQuestionAnswers:salt andOptions:jsonstr andToView:self];
  296. }
  297. }
  298. }
  299. else
  300. {
  301. [SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"%@",[dict objectForKey:@"resultMsg"]]];
  302. }
  303. if( [aDownload.action isEqualToString:act_UserLogout] ){
  304. //[self performSelector:@selector(doSwitch) withObject:nil afterDelay:1];
  305. }
  306. return hide_error;
  307. }
  308. -(void)backButtonClicked:(UIButton *)sender
  309. {
  310. [g_navigation dismissViewController:self animated:YES];
  311. }
  312. -(void)initNavigationView
  313. {
  314. self.navigationView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT>=812?88:64)];
  315. self.navigationView.backgroundColor = [UIColor whiteColor];
  316. [self.view addSubview:self.navigationView];
  317. UILabel * titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, JX_SCREEN_TOP - 40, JX_SCREEN_WIDTH, 40)];
  318. titleLabel.text = @"每日答题";
  319. titleLabel.textColor = [UIColor blackColor];
  320. titleLabel.font = [UIFont systemFontOfSize:18.0f];
  321. titleLabel.textAlignment = NSTextAlignmentCenter;
  322. [self.navigationView addSubview:titleLabel];
  323. self.backButton = [UIButton buttonWithType:UIButtonTypeCustom];
  324. self.backButton.frame = CGRectMake(15, 30, 30, 30);
  325. if(JX_SCREEN_HEIGHT >= 812)
  326. {
  327. self.backButton.frame = CGRectMake(15, 45, 30, 30);
  328. }
  329. [self.backButton setImage:[UIImage imageNamed:@"title_back_black"] forState:UIControlStateNormal];
  330. [self.backButton addTarget:self action:@selector(backButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  331. [self.navigationView addSubview:self.backButton];
  332. }
  333. -(void)initComponents
  334. {
  335. 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))];
  336. self.scrollView.backgroundColor = self.view.backgroundColor;
  337. self.scrollView.contentSize = CGSizeMake(JX_SCREEN_WIDTH, self.scrollView.frame.size.height);
  338. [self.view addSubview:self.scrollView];
  339. UIImageView * backView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, 0.68*JX_SCREEN_WIDTH)];
  340. backView.image = [UIImage imageNamed:@"questionBacks"];
  341. [self.scrollView addSubview:backView];
  342. backView.userInteractionEnabled = YES;
  343. UIButton * postButton = [UIButton buttonWithType:UIButtonTypeCustom];
  344. postButton.frame = CGRectMake(JX_SCREEN_WIDTH - 70 - 15, backView.frame.size.height - 30, 70, 30);
  345. [postButton setBackgroundColor:[UIColor colorWithRed:253/255.0f green:219/255.0f blue:173/255.0f alpha:1.0f]];
  346. [postButton setTitle:@"提交" forState:UIControlStateNormal];
  347. [postButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  348. [postButton.titleLabel setFont:[UIFont systemFontOfSize:13.0f]];
  349. [postButton.layer setCornerRadius:5.0f];
  350. [postButton.layer setMasksToBounds:YES];
  351. [postButton addTarget:self action:@selector(postButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  352. [backView addSubview:postButton];
  353. // if(!self.ifAnswer.boolValue)
  354. // {
  355. // postButton.userInteractionEnabled = NO;
  356. // }
  357. // else
  358. // {
  359. // postButton.userInteractionEnabled = YES;
  360. // }
  361. 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))];
  362. questionView.image = [UIImage imageNamed:@"questionImage"];
  363. [self.scrollView addSubview:questionView];
  364. questionView.userInteractionEnabled = YES;
  365. self.questionTitle = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, questionView.frame.size.width, 40)];
  366. self.questionTitle.text = @"";
  367. self.questionTitle.textColor = [UIColor colorWithRed:115/255.0f green:20/255.0f blue:5/255.0f alpha:1.0f];
  368. self.questionTitle.font = [UIFont boldSystemFontOfSize:15.0f];
  369. self.questionTitle.textAlignment = NSTextAlignmentCenter;
  370. [questionView addSubview:self.questionTitle];
  371. self.questionLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 40, questionView.frame.size.width - 30, 40)];
  372. self.questionLabel.text = @"";
  373. self.questionLabel.numberOfLines = 0;
  374. self.questionLabel.textColor = self.questionTitle.textColor;
  375. self.questionLabel.font = [UIFont systemFontOfSize:15.0f];
  376. [questionView addSubview:self.questionLabel];
  377. 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];
  378. self.questionTable.dataSource = self;
  379. self.questionTable.delegate = self;
  380. self.questionTable.separatorStyle = UITableViewCellSeparatorStyleNone;
  381. self.questionTable.backgroundColor = [UIColor clearColor];
  382. [questionView addSubview:self.questionTable];
  383. if([self.ifAnswer isEqualToString:@"NO"])
  384. {
  385. self.questionTable.userInteractionEnabled = NO;
  386. }
  387. else
  388. {
  389. self.questionTable.userInteractionEnabled = YES;
  390. }
  391. UIButton * preButton = [UIButton buttonWithType:UIButtonTypeCustom];
  392. preButton.frame = CGRectMake(JX_SCREEN_WIDTH/2 - 80 - 50, questionView.frame.origin.y + questionView.frame.size.height + 15, 80, 30);
  393. [preButton setBackgroundColor:[UIColor colorWithRed:253/255.0f green:219/255.0f blue:173/255.0f alpha:1.0f]];
  394. [preButton setTitle:@"上一题" forState:UIControlStateNormal];
  395. [preButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  396. [preButton.titleLabel setFont:[UIFont systemFontOfSize:13.0f]];
  397. [preButton.layer setCornerRadius:5.0f];
  398. [preButton.layer setMasksToBounds:YES];
  399. [preButton addTarget:self action:@selector(preButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  400. preButton.alpha =1.0f;
  401. [self.scrollView addSubview:preButton];
  402. UIButton * nextButton = [UIButton buttonWithType:UIButtonTypeCustom];
  403. nextButton.frame = CGRectMake(JX_SCREEN_WIDTH/2 + 50, preButton.frame.origin.y, 80, 30);
  404. [nextButton setBackgroundColor:[UIColor colorWithRed:253/255.0f green:219/255.0f blue:173/255.0f alpha:1.0f]];
  405. [nextButton setTitle:@"下一题" forState:UIControlStateNormal];
  406. [nextButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  407. [nextButton.titleLabel setFont:[UIFont systemFontOfSize:13.0f]];
  408. [nextButton.layer setCornerRadius:5.0f];
  409. [nextButton.layer setMasksToBounds:YES];
  410. [nextButton addTarget:self action:@selector(nextButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  411. nextButton.alpha = 1.0f;
  412. [self.scrollView addSubview:nextButton];
  413. self.scrollView.contentSize = CGSizeMake(JX_SCREEN_WIDTH, preButton.frame.origin.y + preButton.frame.size.height + 20);
  414. }
  415. -(void)nextButtonClicked:(UIButton *)sender
  416. {
  417. _currentSort ++;
  418. if (_currentSort>_questionArr.count-1) {
  419. _currentSort=(int)_questionArr.count;
  420. UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"当前已是最后一题了" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
  421. [alert show];
  422. return;
  423. }
  424. self.questionTable.userInteractionEnabled=YES;
  425. [_firstArr removeAllObjects];
  426. _indexRow=100;
  427. _indexRightRow=100;
  428. [_questionArr enumerateObjectsUsingBlock:^(QustionJX * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  429. //if ([obj.sort intValue]==_currentSort) {
  430. if ( _currentSort == idx) {
  431. [_firstArr addObject:obj];
  432. self.questionTitle.text = obj.title;
  433. }
  434. }];
  435. [_saveSelectIndexArr enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  436. QustionJX *modelJx=obj[@"option"];
  437. //if (( [modelJx.title isEqualToString:self.questionTitle.text])&& obj[@"option"]!=nil) {
  438. if (( [modelJx.title isEqualToString:self.questionTitle.text])&& obj[@"option"]!=nil) {
  439. _indexRightRow=[obj[@"rightRow"] intValue];
  440. _indexRow=[obj[@"selectIndex"] intValue];
  441. }
  442. if ( _currentSort == idx) {
  443. _indexRightRow=idx;
  444. _indexRow=idx;
  445. }
  446. }];
  447. [self.questionTable reloadData];
  448. }
  449. /** 上一题*/
  450. -(void)preButtonClicked:(UIButton *)sender
  451. {
  452. self.questionTable.userInteractionEnabled=YES;
  453. if(_currentSort > 0)
  454. {
  455. self.currentSort --;
  456. [_firstArr removeAllObjects];
  457. _indexRightRow=100;
  458. _indexRow=100;
  459. [_questionArr enumerateObjectsUsingBlock:^(QustionJX * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  460. // if ([obj.sort intValue]==_currentSort) {
  461. if (_currentSort ==idx) {
  462. [_firstArr addObject:obj];
  463. self.questionTitle.text = obj.title;
  464. }
  465. }];
  466. NSMutableArray *temp=[NSMutableArray array];
  467. [_saveSelectIndexArr enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  468. NSLog(@"%@",obj);
  469. // if (([obj[@"currentSort"] intValue]==_currentSort)
  470. QustionJX *modelJx=obj[@"option"];
  471. if (( [modelJx.title isEqualToString:self.questionTitle.text])&& obj[@"option"]!=nil) {
  472. //self.questionTable.userInteractionEnabled=NO;
  473. _indexRightRow=[obj[@"rightRow"] intValue];
  474. _indexRow=[obj[@"selectIndex"] intValue];
  475. [temp addObject:obj[@"option"]];
  476. _firstArr= temp;
  477. }else{
  478. self.questionTable.userInteractionEnabled=YES;
  479. }
  480. }];
  481. [self.questionTable reloadData];
  482. }
  483. return;
  484. //UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"当前是第一题了" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
  485. // [alert show];
  486. }
  487. -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  488. {
  489. if (alertView.tag==3000) {
  490. [g_navigation popToViewController:[JXApplyViewController class] animated:YES];
  491. return;
  492. }
  493. if(alertView.tag == 1000)
  494. {
  495. if(buttonIndex==0){
  496. return;
  497. }
  498. [g_navigation popToViewController:[JXApplyViewController class] animated:YES];
  499. }
  500. else if(alertView.tag == 10000)
  501. {
  502. self.currentSort ++;
  503. for(NSDictionary * dictionary in self.questionArray)
  504. {
  505. NSString * questionSort = [NSString stringWithFormat:@"%@",[dictionary objectForKey:@"sort"]];
  506. if(questionSort.intValue == self.currentSort)
  507. {
  508. NSString * questionTitle = [NSString stringWithFormat:@"第%@题:%@",questionSort,[dictionary objectForKey:@"title"]];
  509. NSString * questionDesc = [NSString stringWithFormat:@"%@",[dictionary objectForKey:@"desc"]];
  510. if(questionTitle != nil && questionTitle.length != 0 && ![questionTitle isEqualToString:@"(null)"] && ![questionTitle isEqualToString:@"<null>"])
  511. {
  512. self.questionTitle.text = questionTitle;
  513. }
  514. if(questionDesc != nil && questionDesc.length != 0 && ![questionDesc isEqualToString:@"(null)"] && ![questionDesc isEqualToString:@"<null>"])
  515. {
  516. self.questionLabel.text = questionDesc;
  517. }
  518. self.currentQuestion = dictionary;
  519. break;
  520. }
  521. }
  522. [self.questionTable reloadData];
  523. }
  524. }
  525. @end