收到NSNotification但未调用方法

时间:2013-12-10 18:58:06

标签: ios iphone nsnotificationcenter nsnotifications nsnotification

我将UIViewController对象的通知发布到UIView对象。调用通知但不调用其方法“playSound”。

以下是我的代码,并提前致谢:

@interface SettingsViewController : UIViewController <MFMailComposeViewControllerDelegate>
{
    MFMailComposeViewController *mailComposer;

}

- (IBAction)btnSoundClicked:(id)sender {
    if(self.btnSound.on)
    {
        NSLog(@"Swith On");
        [[NSNotificationCenter defaultCenter] postNotificationName:@"soundStatus" object:self.btnSound];
    }
    else
    {
        NSLog(@"Switch Off");
    }
}





@interface IAPuzzleBoardView : UIView <AVAudioPlayerDelegate> {

}
- (void)movingThisTile:(CGPoint)tilePoint {

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(playSound:)
                                             name:@"soundStatus"
                                           object:nil];
}
-(void) playSound : (NSNotification *) notification
{
    if ([[notification name] isEqualToString:@"soundStatus"])
    {
        NSString *path = [[NSBundle mainBundle] pathForResource:@"move" ofType:@"wav"];
        theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
        theAudio.delegate = self;
        [theAudio play];
    }
}

0 个答案:

没有答案