如何让我的NSNotification触发选择器?

时间:2010-06-11 02:02:48

标签: iphone mpmovieplayercontroller nsnotifications nsnotification

以下是代码:

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSURL *musicURL = [NSURL URLWithString:@"http://live-three2.dmd2.ch/buureradio/buureradio.m3u"];

    if([musicURL scheme])
    {
        MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:musicURL];
        if (mp)
        {
            // save the music player object
            self.musicPlayer = mp;
            [mp release];

            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(popBack:) name:@"MPMoviePlayerDidExitFullscreenNotification" object:nil];

            // Play the music!
            [self.musicPlayer play];
        }
    }   
}

-(void)popBack:(NSNotification *)note
{
    [self.navigationController popToRootViewControllerAnimated:YES];
}

永远不会调用选择器方法。我只想在电影播放器​​上按下“完成”按钮时弹回根菜单。我在选择器中放了一个NSLog来检查它是否被调用,什么都没有。音乐很好玩。有什么想法吗?

1 个答案:

答案 0 :(得分:1)

这应该有效

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(popBack:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];