I have this method that usually works, but lately it has been giving me trouble.
What I am trying to do is to switch views without any animation to the switch. For some reason, whenever I switch views, the old screen leaves some stuff behind, such as a button or a text field.
How do I get those to go away every time I switch views?
Here is what I have so far
.h
@class HighScoreViewController;
@interface StartUpScreen : UIViewController {
HighScoreViewController *highScoreViewController;
@property (nonatomic, retain) HighScoreViewController *highScoreViewController;
@end
.m
#import "HighScoreViewController.h"
@implementation StartUpScreen
-(void) viewDidLoad {
UIButton *highScoreButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
highScoreButton.frame = CGRectMake(219, 0, 99, 55);
[highScoreButton addTarget:self
action:@selector(goToHighScoresViewController)
forControlEvents:UIControlEventTouchDown];
[self.view addSubview:highScoreButton];
}
-(void)goToHighScoresViewController {
HighScoreViewController *highScore = [[HighScoreViewController alloc] initWithNibName:@"HighScoreViewController" bundle:nil];
self.highScoreViewController = highScore;
//[self presentModalViewController:highScore animated:YES];
[self.view insertSubview:highScore.view atIndex:0];
[highScore release];
}
Uncomment the
and comment out the:
Lines and all will be fine and dandy.