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

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -