Resolved Stop user from moving to next question?

Discussion in 'iOS Programming' started by dasmin19, Aug 15, 2014.

  1. dasmin19, Aug 15, 2014
    Last edited: Sep 1, 2014

    dasmin19 macrumors newbie

    Joined:
    Jun 27, 2014
    #1
    I already have if the user get the question correct, then they move on to next question.
    Code:
    if ([question.text isEqual: @"Correct"]){
    
       question.text = Whatever question
    }
    But I don't know the code to stop the user from moving onto next question if it's Wrong? Would it be an else statement?
     
  2. LinusR macrumors regular

    LinusR

    Joined:
    Jan 3, 2011
    #2
    In order to answer your question, we need more information on what your classes and methods look like. Post at least the method in which you use this snippet...
     
  3. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #3
    There wouldn't be an else statement? If they shouldn't move forward then it shouldn't do anything, right?
     
  4. dasmin19 thread starter macrumors newbie

    Joined:
    Jun 27, 2014
    #4
    Correct Artofwarfare, I don't want it to move forward until they make the "correct" answer. Right now if I select the wrong answer and click "Next Question", it moves forward to the next question.
     
  5. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #5
    You haven't shared enough code right now. You haven't even told us what the code you've provided does.
     
  6. JohnsonK macrumors regular

    Joined:
    Mar 6, 2014
    #6
    So when clicking "Next Question" you have to check the answer. If it is correct, make it move forward, else do nothing
     
  7. dasmin19, Aug 17, 2014
    Last edited by a moderator: Aug 17, 2014

    dasmin19 thread starter macrumors newbie

    Joined:
    Jun 27, 2014
    #7
    First I will say I'm new and trying to learn how to create an app. So if the answer is Correct then it is moving forward correctly, when I select Next Question. But it's still moving for; if I get wrong, and click Next Question.

    So I am trying to figure out; what else I need to add after the if statement, I guess? So as JohnsonK said, I need to make it do nothing; if they get it wrong. I don't know the short code to say that or do that?

    This is the end part of my coding:

    Code:
    - (IBAction)answerE:(id)sender {
        
        question.text = @"Wrong!";
        question.textColor = [UIColor redColor];
        
        questionUnder.text = @"Try again!";
        questionUnder.textColor = [UIColor redColor];
    }
    
    - (IBAction)nextQuestion:(id)sender {
        
        if ([question.text isEqual:@"Correct Uh Mun Doe!"]){
            
            question.text = @"Translator for low level programming language were termed as?";
            
            
        }
    }
    @end
     
  8. JohnsonK macrumors regular

    Joined:
    Mar 6, 2014
    #8
    Where is the code that makes it "move forward"?
     
  9. dasmin19 thread starter macrumors newbie

    Joined:
    Jun 27, 2014
    #9
    Heck, I thought the code at the bottom was the part that makes it move forward the "if correct". Then up under that has the next question. What am I not getting in this logic.. Well at this point let go back and read up on my if and else statements.

    Thanks.
     
  10. JohnsonK macrumors regular

    Joined:
    Mar 6, 2014
    #10
    Thats because we don't know what "move forward" means. We are programmers, not magicians :p If you don't explain everything, every detail, there is no way for us to figure out what you mean, what you have coded or whats your idea

    I would suggest you to study programming from the ground up, or else you will end up getting bored and giving up on simple problems like this one
     
  11. dasmin19 thread starter macrumors newbie

    Joined:
    Jun 27, 2014
    #11
    Since I'm new to programming then I get the dunce award.:D Because I'm not understanding what you are needing for me to post. But all app is a Quiz program that asks a user computer questions. and they have to get the correct answer. They have 4 choices. If they get it wrong then they shouldn't be able to move on to the next question until it's correct. Once they make the correct choice, then once they click the Next question button, then it will move onto the next question. That's the best I can explain it. But I will keep on reading the "iOS Programming: The Big Nerd Ranch Guide".

    I tried Googling creating a simple Quiz app. But the one's I saw on youtube, was what I was looking for except one.

    So thanks, will just keep trying and reading. And I won't give up because I like solving issues. But thought I could come here and someone may have done this before or created something similar.

    Peace..;)
     
  12. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #12
    If you're having problem with if/else, then I think even as trivial an app as this is probably beyond your current skill level.

    I'd suggest one of the Learn to Code the Hard Way books, either C or Python, both are free online, before you try to tackle an app again.
     
  13. dasmin19 thread starter macrumors newbie

    Joined:
    Jun 27, 2014
    #13
    Appreciate all the info... Will do.
     
  14. larswik macrumors 68000

    Joined:
    Sep 8, 2006
    #14
    Besides learning the code, which you should, a quick work around is to set the move forward [moveForwardButton setEnable: NO]; When they answer it correctly set it to YES.
     
  15. dasmin19, Aug 26, 2014
    Last edited: Aug 26, 2014

    dasmin19 thread starter macrumors newbie

    Joined:
    Jun 27, 2014
    #15
    Thanks larswik,
    I see you have [moveForwardButton setEnabled: NO]. Okay I'm confused with part of this; my - IBAction is named nextQuestion. When I highlight the button on the view controller; the name is Next Question. So would I change moveForwardButton to [Next Question setEnabled:No]?

    ----------

    Here's 1 of the controllers code; if this would help. But it's still moving forward, even if the answer is incorrect or wrong.

    Code:
    #import "Questions.h"
    
    @interface Questions ()
    
    @end
    
    @implementation Questions
    
    @synthesize answerA, answerB, answerC, answerD,answerE,question;
    
    
    
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
            // Custom initialization
        }
        return self;
    }
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
    	// Do any additional setup after loading the view.
    }
    
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    - (IBAction)buttonOne:(id)sender {
        
        
    }
    
    - (IBAction)buttonTwo:(id)sender {
    }
    
    - (IBAction)buttonThree:(id)sender {
    }
    
    - (IBAction)buttonFour:(id)sender {
    }
    
    - (IBAction)buttonFive:(id)sender {
    }
    - (IBAction)answerA:(id)sender {
        question.text = @"Wrong!";
        question.textColor = [UIColor redColor];
        
    }
    
    - (IBAction)answerB:(id)sender {
        
        question.text = @"Wrong!";
        question.textColor = [UIColor redColor];
    }
    
    - (IBAction)answerC:(id)sender {
        
        
        question.text = @"Correct!";
        question.textColor = [UIColor blueColor];
    }
    
    - (IBAction)answerD:(id)sender {
    
        
        question.text = @"Wrong!";
        question.textColor = [UIColor redColor];
    }
    
    
    
    - (IBAction)answerE:(id)sender {
        
        question.text = @"Wrong!";
        question.textColor = [UIColor redColor];
    }
    
    - (IBAction)nextQuestion:(id)sender {
        
    
        if ([question.text  isEqual: @"Correct"]){
            
            question.text = @"Which of the following languages is more suited to a structured program?";
            
           [moveForwardButton setEnable: YES];
           [moveForwardButton setEnable: NO];
            
                 
        }
    }
    @end
    
     
  16. TheWatchfulOne macrumors 6502

    TheWatchfulOne

    Joined:
    Jun 19, 2009
    #16
    Or better yet, don't even display "Next Question" until they answer the current question correctly.
     
  17. dasmin19 thread starter macrumors newbie

    Joined:
    Jun 27, 2014
    #17
    Finally figured it out. All needed to add was nextQuestion.enabled = YES; and nextQuestion.enabled = NO; for the wrong answer. Then I did the if statement. And it works perfectly!

    How do I make my question resolved?
     
  18. moonman239, Sep 1, 2014
    Last edited: Sep 1, 2014

    moonman239 macrumors 68000

    Joined:
    Mar 27, 2009
    #18
    "Edit" (nearest to original post)->"Go Advanced"->"Resolved" in drop-down menu that appears to the left of "Thread Title"->"Save."
     
  19. AxoNeuron macrumors 65816

    AxoNeuron

    Joined:
    Apr 22, 2012
    Location:
    The Left Coast
    #19
    Don't you have to use the method isEqualToString in order to compare strings?
     
  20. TheWatchfulOne, Sep 2, 2014
    Last edited: Sep 2, 2014

    TheWatchfulOne macrumors 6502

    TheWatchfulOne

    Joined:
    Jun 19, 2009
    #20
    This is true, but looking at his code, I didn't happen to see him comparing strings anywhere. It does appear he is hard coding his view controller to present a particular question; a set of incorrect answers; and the correct answer.

    dasmin19, you only need one view controller capable of displaying any question (Not counting any views you might have for a home screen and/or a score page). It should be driven by a database which contains many questions and answers. You will save yourself much work that way. I recommend Core Data or interact directly with SQLite.

    Nevermind, his code comparing strings is in the original post. Yes, you should use
    Code:
    isEqualToString:
    to compare string values.
    Code:
    isEqual:
    compares memory addresses.
     
  21. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #21
    Please refer to the reference docs, to see if there might be a useful description there.

    In general:
    • == compares memory addresses.
    • isEqual: is a generalized object-equality method, that may be overridden in any class.
    • isEqualToString: is specific to NSString, and does essentially the same thing as isEqual: for this class.
    If there's still a question, I suggest writing a test program to discover the difference (if any) between isEqualToString: and isEqual:.

    One could also google it, e.g. search terms nsstring isequal
     
  22. AxoNeuron macrumors 65816

    AxoNeuron

    Joined:
    Apr 22, 2012
    Location:
    The Left Coast
    #22
    Great information, thanks both of you :)
     

Share This Page