视图控制器的顶部栏按钮不会出现

时间:2011-10-20 12:14:07

标签: iphone xcode4 uinavigationcontroller

我有以下内容:

我将视图控制器推送到这样的navigationController:

 moviePlayer = [[[CustomMoviePlayerViewController alloc] initWithPath:path2] autorelease];
    [self.navigationController pushViewController:moviePlayer animated:YES];
    self.navigationController.navigationBarHidden = YES;
    [moviePlayer readyPlayer];

并加载了顶部栏上没有按钮的视频。

http://i54.tinypic.com/i73q08.png

在我回到上一个视图并再次尝试加载此视图后,它会显示:

http://i55.tinypic.com/2mqol55.png

突然,完成按钮出现在顶部栏中。

我的问题是为什么它从第一次出现,因为我没有改变代码。

这是推入堆栈的viewController的代码:

@implementation CustomMoviePlayerViewController

- (void) moviePlayerLoadStateChanged:(NSNotification*)notification 
{
    // Unless state is unknown, start playback
    if ([mp loadState] != MPMovieLoadStateUnknown)
    {
        // Remove observer
        [[NSNotificationCenter  defaultCenter] 
         removeObserver:self
         name:MPMoviePlayerLoadStateDidChangeNotification 
         object:nil];
        [[mp view] setFrame:CGRectMake(0, -20, 320, 400)];
        [mp setScalingMode:MPMovieScalingModeAspectFill];

        // Add movie player as subview
        [[self view] addSubview:[mp view]];   

        // Play the movie
        [mp play];
    }
}

- (void) moviePlayBackDidFinish:(NSNotification*)notification 
{    
    [[UIApplication sharedApplication] setStatusBarHidden:YES];

    // Remove observer
    [[NSNotificationCenter  defaultCenter] 
     removeObserver:self
     name:MPMoviePlayerPlaybackDidFinishNotification 
     object:nil];

    [self.navigationController popViewControllerAnimated:YES];  
}

- (void) readyPlayer
{
    mp =  [[MPMoviePlayerController alloc] initWithContentURL:movieURL];

    if ([mp respondsToSelector:@selector(loadState)]) 
    {
        // Set movie player layout
        [mp setControlStyle:MPMovieControlStyleFullscreen];
        [mp setFullscreen:YES];

        // May help to reduce latency
        [mp prepareToPlay];

        // Register that the load state changed (movie is ready)
        [[NSNotificationCenter defaultCenter] addObserver:self 
                                                 selector:@selector(moviePlayerLoadStateChanged:) 
                                                     name:MPMoviePlayerLoadStateDidChangeNotification 
                                                   object:nil];
    }  
    else
    {
        // Register to receive a notification when the movie is in memory and ready to play.
        [[NSNotificationCenter defaultCenter] addObserver:self 
                                                 selector:@selector(moviePreloadDidFinish:) 
                                                     name:MPMoviePlayerContentPreloadDidFinishNotification 
                                                   object:nil];
    }

    // Register to receive a notification when the movie has finished playing. 
    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(moviePlayBackDidFinish:) 
                                                 name:MPMoviePlayerPlaybackDidFinishNotification 
                                               object:nil];
}

谢谢!:)

0 个答案:

没有答案