Reputation: 567
I have a project with many views controllers in the storyboard. I would like to have an audio controller (same on all views). How could I do to control it independete screen that was?
The idea is that the audio start playing qaundo the application opens and the other screens I can give stop or play.
Sorry my english is terrible. Someone could help me please? Thanks
Upvotes: 1
Views: 387
Reputation: 2430
first of all in your AppDelegate.h file write this code below #import UIKit/UIKit.h
#define APPDELEGATE ((AppDelegate*)[[UIApplication sharedApplication] delegate])
and now import your AppDelegate.h file to your "projectname-Prefix.pch"
now you'll have access of your AppDelegate class in all the viewControllers in your app.
so now create the player start and stop methods in your AppDelegate.m file and call it on any viewController you want as per your requirement.
Hope it helps you and if you have any confusion you can ask me.
Upvotes: 0
Reputation: 9169
A UIViewController
provides life-cycle and state management of a UIView
, and can contain child view controllers. Similarly, the underlying UIView can contain a child UIView.
If your player is implemented in a UIViewController
, you can simply instantiate it once and then move it to the currently visible parent UIViewController
(it can only the the child of a single view controller at any one time) using the
- (void)addChildViewController:(UIViewController *)childController
method of UIViewController
Container view controllers such as UINavigationController
or UITabBarController
provide delegate interfaces (UINavigationControllerDelegate
and UITabBarDelegate
respectively) which allow you to get notifications when the currently visible view is about to change.
For the UINavigationController
you would implement - (void) navigationController:willShowViewController:animated
to attach the player's view controller to willShowViewController
.
Upvotes: 1