views:

84

answers:

4

How come this won't switch views for me? When I click the button it does nothing...

-(IBAction)howtoplayButtonClicked{
    howToPlayViewController = [[HowToPlayViewController alloc] initWithNibName:@"HowToPlayViewController" bundle:nil];
    [self.navigationController pushViewController:howToPlayViewController animated:YES];
    [HowToPlayViewController release];

}

in the .h file I have this...

#import <UIKit/UIKit.h>
#import "HowToPlayViewController.h"

@interface PopToItViewController : UIViewController {

    HowToPlayViewController *howToPlayViewController;

}

-(IBAction)howtoplayButtonClicked;

@end
A: 

Make sure self.navigationController!=nil

how do i make sure of that?
NextRev
for example assert(self.navigationController != nil)
+2  A: 

For starters, this is wrong:

[HowToPlayViewController release];

It should be:

[howToPlayViewController release];

I don't know what sending a release message to a Class does.

Rob Jones
switched it howtoPlayViewController and it's still not doing anything
NextRev
Hah! Good catch! I scanned right past that.
TechZen
+3  A: 

Your action method...

-(IBAction)howtoplayButtonClicked;

... should look like this:

-(IBAction)howtoplayButtonClicked:(id) sender;

In it's improper form it might not be called. If correcting the form does not work, you should:

  1. Put a breakpoint or log statement in the method to see if it ever gets called. If it does not check you IBConnections to make sure the button is wired to the method.
  2. You don't need howToPlayViewController set as property if your initializing it from nib and then releasing it. Generally you would only use a property if you wanted to wire it up in Interface Builder in which case it should be defined like so:

    IBOutlet HowToPlayViewController *howToPlayViewController;

TechZen
A: 

well switching views is very easy. First create two buttons in both of your views (make sure you have both an h and m file of your views) then create your switching action which should look like this:

SecondView *secondViewController = [[SecondView alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:secondViewController animated:YES];

and the back action:

[self.parentViewController dismissModalViewControllerAnimated:YES];

Ravin455