iOS : How to reference a music background from a singleton class?

前端 未结 3 1314
闹比i
闹比i 2020-12-22 08:53

I have done a singleton class called MyBgMusic.h & MyBgMusic.m. How to reference that singleton class to my SecondViewController or the rest of the XIB.

Here is

相关标签:
3条回答
  • 2020-12-22 09:05

    You have to import your class and reference it wherever you want using this line :

    [[MyBgMusic sharedManager] toggleMusic]
    

    If you want, you can add even property and reference it without create an instance of your class.

    0 讨论(0)
  • 2020-12-22 09:21

    In SecondViewController you should call [[MyBgMusic sharedInstance] toggleMusic];in the IBAction when you want to toggle music. Just as you used self.player.

    0 讨论(0)
  • 2020-12-22 09:25

    Create an IBAction in your SecondViewController hook up the xib then in code then have it call

    [[MyBgMusic sharedInstance] toggleMusic];
    
    0 讨论(0)
提交回复
热议问题