是否可以检查是否按下了完成按钮

时间:2010-12-09 13:00:25

标签: iphone objective-c

我收到有关电影播放器​​的通知:

[[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]; 
}

在这个处理程序方法中,我想检查完成按钮是否是发件人。因为这个方法我有两个发件人。怎么检查这个?

4 个答案:

答案 0 :(得分:3)

每个文档:MPMoviePlayerPlaybackDidFinishNotification userInfo字典必须包含NSNUmber MPMoviePlayerPlaybackDidFinishReasonUserInfoKey键,表示播放完成的原因。它的可能值:

enum {
   MPMovieFinishReasonPlaybackEnded,
   MPMovieFinishReasonPlaybackError,
   MPMovieFinishReasonUserExited
};

答案 1 :(得分: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.
}

就是这样。

答案 2 :(得分:0)

使用按钮添加标签并根据标签放置条件。

或通过

检查
if([sender isEqual:btn1])
{

}
else 
{

}

答案 3 :(得分:0)

这是一个旧线程,但我在寻找解决方案时偶然发现它,并且接受的解决方案没有显示最终代码。 这是你要做的:

- (void) moviePlayBackDidFinish:(NSNotification*)notification

{
    的NSLog(@ “moviePlayBackDidFinish”);

// Remove observer

[[NSNotificationCenter defaultCenter] removeObserver:self                             名称: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
 */

}