Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 从模式视图控制器返回-是否有检测方法?_Iphone_Objective C_Uiviewcontroller - Fatal编程技术网

Iphone 从模式视图控制器返回-是否有检测方法?

Iphone 从模式视图控制器返回-是否有检测方法?,iphone,objective-c,uiviewcontroller,Iphone,Objective C,Uiviewcontroller,不知是否有人能帮助我。我有一个设置,其中一个主菜单显示作为模态视图控制器的主游戏。此时,它也停止播放主菜单音乐 问题是,当游戏视图控制器自行关闭(例如,当用户退出游戏)并返回主菜单时,我无法让主菜单音乐重新开始播放 有什么方法可以让主菜单中的音乐重新开始播放吗?例如,当主游戏解散时调用的委托方法 谢谢 马丁你可以通过NotificationManager来完成 // set up notification [[NSNotificationCenter defaultCenter] addObse

不知是否有人能帮助我。我有一个设置,其中一个主菜单显示作为模态视图控制器的主游戏。此时,它也停止播放主菜单音乐

问题是,当游戏视图控制器自行关闭(例如,当用户退出游戏)并返回主菜单时,我无法让主菜单音乐重新开始播放

有什么方法可以让主菜单中的音乐重新开始播放吗?例如,当主游戏解散时调用的委托方法

谢谢


马丁

你可以通过NotificationManager来完成

// set up notification
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(playMusic:) 
                                         name:@"musicNotification"
                                         object:nil];

// send notification
[[NSNotificationCenter defaultCenter] postNotificationName:@"musicNotification"
                                         object:self];
// clean up notification
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];

- (void) playMusic:(NSNotification *) notification
{
    // play the music here
    if ([[notification name] isEqualToString:@"musicNotification"])
        NSLog (@"Received musicNotification!");
}