2010-12-09 124 views
0

我有通知在電影播放:是否可以檢查是否完成按鈕被按下

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

而且它的處理程序:

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

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

[self dismissModalViewControllerAnimated:YES]; 
} 

在這裏,在這個處理方法我想檢查DONE按鈕是發件人。因爲我有兩個發件人這個方法。如何檢查這個?

回答

3

每文檔:MPMoviePlayerPlaybackDidFinishNotification USERINFO字典必須包含的NSNumber爲MPMoviePlayerPlaybackDidFinishReasonUserInfoKey鍵指示原因播放結束。其可能的值:

enum { 
    MPMovieFinishReasonPlaybackEnded, 
    MPMovieFinishReasonPlaybackError, 
    MPMovieFinishReasonUserExited 
}; 
0

用按鈕添加標籤並根據標籤放置條件。

或檢查

由IF([發送isEqual:方法BTN1]) {

} 
else 
{ 

} 
1

你首先需要在行動前指定標籤的按鈕,然後檢查發件人的價值標籤。

只需添加這些代碼行

- (void) moviePlayBackDidFinish:(NSNotification*)notification { 
     NSInteger anyInteger = [sender tag]; 
     //Now check the value of the anyInteger and write the code accordingly. 
    //switch case or if condition whatever you want. 
} 

完蛋了。

阿迪亞

+0

但如果是 '發件人'? – 1110 2010-12-09 13:14:28

0

這是一個古老的線程,但我偶然發現了它,而尋找解決的辦法,並接受的解決方案不顯示最後的代碼。 這裏是你必須做的:

- (void) moviePlayBackDidFinish:(NSNotification*)notification 

{
的NSLog(@ 「moviePlayBackDidFinish」);

// Remove observer 

[[NSNotificationCenter defaultCenter] removeObserver:自 名:MPMoviePlayerPlaybackDidFinishNotification 對象:無];

NSInteger movieFinishReason= [[[notification userInfo]objectForKey: 
           MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] intValue]; 


if(movieFinishReason == 2 || movieFinishReason == 1 || movieFinishReason == 0){ 
    [self dismissViewControllerAnimated:YES completion:nil]; 
} 
/* 
MPMovieFinishReasonPlaybackEnded = 0,//played movie sucessfuly. 
MPMovieFinishReasonPlaybackError = 1, //error in playing movie 
MPMovieFinishReasonUserExited = 2; //user quitting the application/user pressed done button 
*/ 

}

相關問題