Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

dasmin19

macrumors newbie
Original poster
Jun 27, 2014
24
0
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?
 
Last edited:
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...
 
There wouldn't be an else statement? If they shouldn't move forward then it shouldn't do anything, right?
 
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.
 
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.

You haven't shared enough code right now. You haven't even told us what the code you've provided does.
 
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.

So when clicking "Next Question" you have to check the answer. If it is correct, make it move forward, else do nothing
 
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
 
Last edited by a moderator:
Where is the code that makes it "move forward"?

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.
 
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.

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
 
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

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..;)
 
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.
 
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.

Appreciate all the info... Will do.
 
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.
 
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
 
Last edited:
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?
 
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?

"Edit" (nearest to original post)->"Go Advanced"->"Resolved" in drop-down menu that appears to the left of "Thread Title"->"Save."
 
Last edited:
Don't you have to use the method isEqualToString in order to compare strings?

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.
 
Last edited:
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.
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
 
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.

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
Great information, thanks both of you :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.