ios - Connect UISwitch with event in other view controller -


i have 2 view controller first 1 main view controller , run music when view controller load , other view controller settings content uiswitch want when user go setting view controller , turn switch off music stop in main view here code

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 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 looping forever  //    audioplayer.volume = 0.5; // 0.0 - no volume; 1.0 full volume //    nslog(@"%f seconds played far", audioplayer.currenttime); //    audioplayer.currenttime = 5; // jump 10 second mark //    [audioplayer pause]; //    [audioplayer stop]; // not reset currenttime; sending play resumes  if (audioplayer == nil) {     nslog(@"no audio player"); } else {     [audioplayer play]; } //end audio sound 

use nsnotificationcenter

first view controller, add observer switch notification, second view controller post notification when switch switched.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -