【问题标题】:How do I make my NSNotification trigger a selector?如何让我的 NSNotification 触发选择器?
【发布时间】:2010-06-11 02:02:48
【问题描述】:

代码如下:

- (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 来检查它是否被调用,什么都没有。音乐播放得很好。有什么想法吗?

【问题讨论】:

    标签: iphone mpmovieplayercontroller nsnotifications nsnotification


    【解决方案1】:

    这应该可以工作

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-27
      • 1970-01-01
      • 2019-07-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多