1

下面的代碼:如何讓我的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

這應該工作

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

booyah。謝謝。我有的只有3.2。多數民衆贊成... – marty 2010-06-11 02:41:53