ios - How to retain ViewContoller when popped Objective -C -


how retain view contoller when popped stack ?

basically have mp3 player view controller. when i'm in view controller, can play music. when music playing , navigate different controller, music stops playing, , when navigate controller, starts instance of it. guess fix, retain view controller ?

this how initiate music player view controller:

nsstring *songlargeartworkurl = [self.songartworkurl stringbyreplacingoccurrencesofstring:@"large" withstring:@"crop"]; musicplayerviewcontroller *musicplayer = [[musicplayerviewcontroller alloc] init]; musicplayer.songname = self.teststring; musicplayer.songartwork = songlargeartworkurl; musicplayer.songstream = self.songstreamurl; [self.navigationcontroller pushviewcontroller:musicplayer animated:yes]; 

instead of using local variable musicplayerviewcontroller, use instance variable. first time, allocate musicplayer instance. shown below:

nsstring *songlargeartworkurl = [self.songartworkurl stringbyreplacingoccurrencesofstring:@"large" withstring:@"crop"]; if(! musicplayer) {     musicplayer = [[musicplayerviewcontroller alloc] init]; } musicplayer.songname = self.teststring; musicplayer.songartwork = songlargeartworkurl; musicplayer.songstream = self.songstreamurl; [self.navigationcontroller pushviewcontroller:musicplayer animated:yes]; 

the above code makes sure that, first time music player instantiated. subsequent times, pushes same instance of music player


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -