【问题标题】:Returning from dismiss modal view controller - any way to detect?从关闭模式视图控制器返回 - 有什么方法可以检测到?
【发布时间】:2010-11-03 04:08:20
【问题描述】:

想知道是否有人可以帮助我。我有一个设置,主菜单将主游戏显示为模态视图控制器。此时它也停止播放主菜单音乐。

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

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

谢谢,

马丁

【问题讨论】:

    标签: iphone objective-c uiviewcontroller


    【解决方案1】:

    你可以用 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!");
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-08
      • 2011-12-31
      • 2013-01-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多