切换视图控制器,但旧屏幕留在后面

时间:2012-05-24 02:19:17

标签: iphone ios uiview

我有这种方法通常有效,但最近它一直给我带来麻烦。

我要做的是将没有任何动画的视图切换到交换机。出于某种原因,每当我切换视图时,旧屏幕都会留下一些东西,例如按钮或文本字段。

每次切换视图时,如何让它们消失?

这是我到目前为止所拥有的

·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];
}

1 个答案:

答案 0 :(得分:1)

取消注释

[self presentModalViewController:highScore animated:NO];

并注释掉:

[self.view insertSubview:highScore.view atIndex:0];

线条和一切都很好,花花公子。