2011-08-08 64 views
0

MoviePlayerAppDelegate.m查看沒有加載

- (void)applicationDidFinishLaunching:(UIApplication *)application 
{ 
    window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 

    viewController = [[MoviePlayerViewController alloc] init]; 
    [window addSubview:viewController.view]; 
    [window makeKeyAndVisible]; 
} 

MoviePlayerViewController.m

-(void)loadView { 
    //Setup the view. 
    [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]]; 
    [[self view] setBackgroundColor:[UIColor grayColor]]; 
    [[self view] setUserInteractionEnabled:YES]; 

    //Add play button. 
    playButton = [[UIButton alloc] initWithFrame:CGRectMake(53, 212, 214, 36)]; 
    [playButton setBackgroundImage:[UIImage imageNamed:@"playButton.png"] forState:UIControlStateNormal]; 
    [playButton addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside]; 
    [[self view] addSubview:playButton]; 
} 

但不知何故view沒有加載。我在代碼中找不到錯誤。請幫助解決這個問題。提前致謝。

+0

我不確定你是否可以這樣做。但我沒有那樣做。我做了另一個UIViewController類,並在其中播放視頻。 – rptwsthi

+0

window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 這是什麼需要? –

+0

是否將一些視圖分配給aMoviePlayerViewController.view?無論是在代碼或筆尖? – vikingosegundo

回答

0

試試這個:

刪除代碼

window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 

和如下改變addSubView。

[self.window addSubview:viewController.view]; 

[self.window makeKeyAndVisible]; 
0

您可以嘗試在你的頭文件中定義的UIView一則武官它self.view

 
MoviePlayerViewController.h 
UIView *contentView; 

@property (retain, nonatomic) UIView     *contentView; 

MoviePlayerViewController.m 

@synthesize contentView; 

- loadView { 

CGRect screenRect = [[UIScreen mainScreen] applicationFrame]; 

contentView = [[UIView alloc] initWithFrame:screenRect]; 
contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 

self.view = contentView; 
[contentView release]; 
} 

這肯定的作品。