Reputation: 97
This might be a bit confusing so if it is just comment and I will try and rephrase it.
I have 2 ViewControllers (ViewController and Page2ViewController). I have AVFoundation framework working and for an example this is what I'm doing:
//In ViewController.m
[PlaySound1 play];
[PlaySound2 play];
//In Page2ViewController.m
[PlaySound3 play];
[PlaySound4 play];
Each ViewController have a stop function like this:
-(void)Stop{
[PlaySound1 stop];
[PlaySound2 stop];
[PlaySound3 stop];
[PlaySound4 stop];
PlaySound1.currentTime = 0.0;
PlaySound2.currentTime = 0.0;
PlaySound3.currentTime = 0.0;
PlaySound4.currentTime = 0.0;
When you press a button it uses the stop function and plays the sound. My problem is each ViewController will only stop the tracks they hold. I've tried importing the ViewControllers into each other, I've tried copy all the codes to link them to the files into each ViewController but that doesn't work either.
Any ideas?
Thanks.
Upvotes: 0
Views: 61
Reputation: 1025
You really want to check this example on a BOOL variable. This way you can send a ViewController instance also and call their methods:
Link: Passing data between ViewControllers
To pass a BOOL value from ViewControllerA to ViewControllerB we would do the following.
in ViewControllerB.h create a property for the BOOL
@property(nonatomic) BOOL *isSomethingEnabled; in ViewControllerA you need to tell it about ViewControllerB so use an
#import "ViewControllerB.h"
Then where you want to load the view eg. didSelectRowAtIndex or some IBAction you need to set the property in ViewControllerB before you push it onto nav stack.
ViewControllerB *viewControllerB = [[ViewControllerB alloc] initWithNib:@"ViewControllerB" bundle:nil];
viewControllerB.isSomethingEnabled = YES;
[self pushViewController:viewControllerB animated:YES];
This will set isSomethingEnabled in ViewControllerB to BOOL value YES.
Upvotes: 1