连接UISwitch与事件在其他视图控制器
问题描述:
我有2视图控制器的第一个是主视图控制器,并将运行音乐时,视图控制器加载和其他视图控制器是设置内容的UISwitch所以我想要的是当用户去设置视图控制器,并打开关掉那么音乐将在主视图 停在这里是代码连接UISwitch与事件在其他视图控制器
main.h
#import<AVFoundation/AVAudioPlayer.h>
@interface main : UIViewController
{
AVAudioPlayer *audioPlayer;
BOOL didInitialize;
}
的main.m
static BOOL didInitialize = NO;
if (didInitialize == YES)
return;
didInitialize = YES;
//Add Audio Sound to the current View Controller
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/MLGBoxSoundTrack.mp3", [[NSBundle mainBundle] resourcePath]]];
NSError *error;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
audioPlayer.numberOfLoops = -1; // -1 for looping forever
// audioPlayer.volume = 0.5; // 0.0 - no volume; 1.0 full volume
// NSLog(@"%f seconds played so far", audioPlayer.currentTime);
// audioPlayer.currentTime = 5; // jump to the 10 second mark
// [audioPlayer pause];
// [audioPlayer stop]; // Does not reset currentTime; sending play resumes
if (audioPlayer == nil)
{
NSLog(@"No Audio Player");
}
else
{
[audioPlayer play];
}
//End Audio Sound
可以请您提供此问题的代码 – Mahmoud 2014-12-05 20:58:25
网上有很多可用的资源,包括我的答案中包含的链接。 – shim 2014-12-06 05:06:58