Guest User

Untitled

a guest
Oct 17th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 0 0
  1. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  2. static NSString *cellIdentifier = @"challengeTableCell";
  3. cell = (EnrollmentChallengeTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
  4. if (cell == nil) {
  5. cell = [[EnrollmentChallengeTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
  6. }
  7. cell.answerTextfield.delegate = self;
  8.  
  9. if (indexPath.row == 0) {
  10. cell.questionTitleLabel.text = @"Challenge Question 1";
  11. cell.questionLabel.tag = 100;
  12. cell.questionLabel.textColor = [UIColor blackColor];
  13. NSString *user1 = [myDict objectForKey:@"firstQuestion"];
  14. NSLog(@"firstquestion: %@",user1);
  15. }
  16. else if (indexPath.row == 1) {
  17. cell.questionTitleLabel.text = @"Challenge Question 2";
  18. cell.questionLabel.tag = 101;
  19. NSString *user2 = [myDict objectForKey:@"secondQuestion"];
  20. NSLog(@"secondQuestion: %@",user2);
  21.  
  22. }
  23. else {
  24. cell.questionTitleLabel.text = @"Challenge Question 3";
  25. cell.questionLabel.tag = 102;
  26. NSString *user3 = [myDict objectForKey:@"thirdQuestion"];
  27. NSLog(@"thirdQuestion: %@",user3);
  28. }
  29.  
  30. if (cell.questionLabel.tag == 100 || cell.questionLabel.tag == 101 || cell.questionLabel.tag == 102) {
  31. UITapGestureRecognizer* gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectQuestion:)];
  32. [cell.questionLabel setUserInteractionEnabled:YES];
  33. [cell.questionLabel addGestureRecognizer:gesture];
  34. }
  35.  
  36. return cell;
  37. }
  38.  
  39. -(void)selectQuestion:(UITapGestureRecognizer *) sender
  40. {
  41. CGPoint touchLocation = [sender locationOfTouch:0 inView:challengeQuestionsTable];
  42. newIndexPath = [challengeQuestionsTable indexPathForRowAtPoint:touchLocation];
  43. selectQuestionVC = [EnrollmentSelectQuestionViewController instantiate];
  44. selectQuestionVC.questionDelegate = self;
  45. [self presentViewController:selectQuestionVC animated:YES completion:nil];
  46. }
  47.  
  48. #pragma mark - Table Selection Delegate
  49.  
  50. -(void)valueChanged:(NSString *)questionString {
  51. //[challengeQuestionsTable reloadRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationNone];
  52. passedValue = questionString;
  53. NSLog(@"questionvalue: %@",passedValue);
  54. NSLog(@"mydict: %lu",(unsigned long)[myDict count]);
  55. cell = [challengeQuestionsTable cellForRowAtIndexPath:newIndexPath];
  56. NSLog(@"you have selected index: %ld", (long)newIndexPath.row);
  57. [[NSUserDefaults standardUserDefaults] setInteger:newIndexPath.row forKey:@"SelectedIndex"];
  58. [[NSUserDefaults standardUserDefaults] synchronize];
  59.  
  60. // NSInteger numberOfRows = [challengeQuestionsTable numberOfRowsInSection:[indexPath section]];
  61. NSLog(@"indexpath row: %ld",newIndexPath.row);
  62.  
  63. if (newIndexPath.row == 0) {
  64. [myDict setValue:passedValue forKey:@"firstQuestion"];
  65. } else if (newIndexPath.row == 1) {
  66. [myDict setValue:passedValue forKey:@"secondQuestion"];
  67. } else {
  68. [myDict setValue:passedValue forKey:@"thirdQuestion"];
  69. }
  70.  
  71. NSLog(@"mydict: %@",myDict);
  72. NSLog(@"1st: %@",[myDict objectForKey:@"firstQuestion"]);
  73. NSLog(@"2nd: %@",[myDict objectForKey:@"secondQuestion"]);
  74. NSLog(@"3rd: %@",[myDict objectForKey:@"thirdQuestion"]);
  75. }
  76.  
  77. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  78. tableView.deselectRow(at: indexPath, animated: true)
  79. print("selected index :",indexPath.row)
  80.  
  81. let selectedCell = tableView.cellForRow(at: indexPath)
  82. print("did select and the text is (selectedCell?.textLabel?.text)")
  83. let storyboard = UIStoryboard(name: "EnrollmentChallengeQuestions", bundle: nil)
  84. challengeVC = storyboard.instantiateViewController(withIdentifier: "ChallengeQuestions") as! EnrollmentChallengeQuestionsViewController
  85. challengeVC.passedValue = selectedCell?.textLabel?.text
  86. print("text label value: ", challengeVC.passedValue)
  87. questionDelegate?.valueChanged(challengeVC.passedValue)
  88. self.present(challengeVC, animated: true , completion: nil)
  89. }
Add Comment
Please, Sign In to add comment