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

EducationApp

macrumors newbie
Original poster
Aug 17, 2011
18
0
I'm stuck on how to make it so the user has to click one button, and then a second for switching views. I'm trying to make it so the user can change the difficulty of the game, Easy, Medium, or Hard, and then press start to begin. How to I go about doing this. Is it an "if" statement. I've named the buttons btnButton1, btnButton2, btnButton3, btnButton4. Can you supply the code for me to switch views with just the easy option and then start?
The other views are imported as: easyview, mediumview, hardview.
Thanks
 
I know how to change views by clicking one button and then having it change but I'm stuck on how to have it so the Easy button + Ok goes to the Easy page and the medium button + ok goes to the medium button.
I have no idea where to go...
 
Last edited:
-(IBAction)switchview:(id)sender {
easyview *easy = [[easyview alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:easy animated:YES];
}


-(IBAction)btnButton1:(id)sender
{
infoText.text = @"EASY: You have 10 rounds to complete and you are"
" given 60 seconds per round."
" Deal when ready...";
if (infoText.text == @"EASY: You have 10 rounds to complete and you are"
" given 60 seconds per round."
" Deal when ready...") {
-(IBAction)btnButton4 = switchview;
}
}
-(IBAction)btnButton4 = switchview doesn't work...
 
Last edited:
Please surround your code with
Code:
 tags so that we can read it, and post the entire code for the class you are having trouble with.
 
//
Code:
#import "thirdview.h"
#import "secondview.h"
#import "easyview.h"
#import "mediumview.h"
#import "hardview.h"

@implementation thirdview
@synthesize infoText;


-(IBAction)switchview:(id)sender {
    easyview *easy = [[easyview alloc] initWithNibName:nil bundle:nil];
    [self presentModalViewController:easy animated:YES];
}


-(IBAction)btnButton1:(id)sender
{
    infoText.text = @"EASY: You have 10 rounds to complete and you are" 
        " given 60 seconds per round."      
        "                                                                   Deal when ready...";
    if (infoText.text == @"EASY: You have 10 rounds to complete and you are" 
        " given 60 seconds per round."      
        "                                                                   Deal when ready...") {

    }
   }



-(IBAction)btnButton2:(id)sender
{
    infoText.text = @"MEDIUM: You have 15 rounds to complete and you are given 40 seconds per round."
    "                                                           Deal when ready...";
}


-(IBAction)switchview1:(id)sender {
    mediumview *medium = [[mediumview alloc] initiWithNibName:nil bundle:nil];
    [self presentModalViewController:medium animated:YES];
}




-(IBAction)btnButton3:(id)sender
{
    infoText.text = @"HARD: You have 20 rounds to complete and you are given 20 seconds per round."                                       
    "                                                           Deal when ready...";
}



-(IBAction)switchback:(id)sender {
    secondview *second = [[secondview alloc] initWithNibName:nil bundle:nil];
    [self presentModalViewController:second animated:YES];
}




- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [label setFont: [UIFont fontWithName:@"Speedline" size:24]];
    [super viewDidLoad];
        infoText.text = @"Welcome to Math Jack!";
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{

    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

-(void)dealloc {
    [super dealloc];
    
    [infoText release];
    
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}


@end

//




Didn't complete the if statement because when I put "-(IBAction)btnButton4 = switchview;" in, there is an error with the IBAction.
 
Code:
#import <UIKit/UIKit.h>

@interface thirdview : UIViewController {
    
    UILabel *infoText;
    IBOutlet UILabel *label;


}
-(IBAction)switchback:(id)sender;
-(IBAction)switchview:(id)sender;
-(IBAction)switchview1:(id)sender;

@property (nonatomic, retain) IBOutlet UILabel *infoText;

-(IBAction)btnButton1:(id)sender;
-(IBAction)btnButton2:(id)sender;
-(IBAction)btnButton3:(id)sender;
-(IBAction)btnButton4:(id)sender;

@end
 
That code doesn't answer my question. I want to know which of those IBAction methods you have wired to the button presses in Interface Builder.

I'm going to assume that it's the btnButton1-4 ones that are wired to your four buttons. It looks like you want the code in the switchview method to execute after the code in btnButton1- so why not just put the code that is currently in the switchview method in btnButton1, or call the switchview method at the end of btnButton1?

P.S. You need to learn proper Objective-C naming conventions.
 
It is because the text shows up and they need to first press Easy, read the infoText, if they want to play that difficulty, "Deal" takes them there, if they want it harder, they go to Medium or Hard
 
I'd like to start off with thanking you for helping me. The Deal button is btnButton4 which can be seen on the thirdview.m but I have not put it in the thirdview.h. All the switchviews go through it though.
 
Well the concise answer to your question is that you should probably have an instance variable that stores the user's current difficulty selection, and when Deal is pressed, you will look at that variable and decide what view to load with an if or switch statement. This means you will only need 4 IBAction methods.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.