Note that there are some explanatory texts on larger screens.

plurals
  1. POLoading presentModalViewController in ViewDidAppear causes EXC_BAD_ACCESS
    text
    copied!<p>In the Follwoing ViewControllerClass I get EXC_BAD_ACCESS when trying to call presentModalViewController in ViewDidAppear method. </p> <pre><code>#import "SounderViewController.h" #import "ASIFormDataRequest.h" #import "ASIHTTPRequest.h" #import "JSON.h" #import "InfoViewController.h" @implementation SounderViewController @synthesize ipod; @synthesize ivc; @synthesize title_lb, artist_lb, check; -(IBAction)showCurrentSongInfo{ MPMediaItem * song = [ipod nowPlayingItem]; NSString * title = [song valueForProperty:MPMediaItemPropertyTitle]; NSString * artist = [song valueForProperty:MPMediaItemPropertyArtist]; title_lb.text = title; artist_lb.text = artist; } -(void)playbackStateChanged: (NSNotification*) notification{ [self showCurrentSongInfo]; NSLog(@"Playback state: %@",[notification name]); if (ipod.playbackState != MPMusicPlaybackStatePlaying) { NSLog(@"Is not playing"); [self presentModalViewController:self.ivc animated:YES]; }else if (ipod.playbackState == MPMusicPlaybackStatePlaying) { NSLog(@"Is playing"); [self dismissModalViewControllerAnimated:YES]; } } -(void)nowPlayingItemChanged: (NSNotification*) notification{ [self showCurrentSongInfo]; NSLog(@"Playing item changed: %@",[notification name]); } - (void)viewDidLoad { [super viewDidLoad]; self.ivc = [[InfoViewController alloc] initWithNibName:@"InfoViewController" bundle:nil]; self.ipod = [MPMusicPlayerController iPodMusicPlayer]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector (playbackStateChanged:) name:@"MPMusicPlayerControllerPlaybackStateDidChangeNotification" object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector (nowPlayingItemChanged:) name:@"MPMusicPlayerControllerNowPlayingItemDidChangeNotification" object:nil]; [[MPMusicPlayerController iPodMusicPlayer] beginGeneratingPlaybackNotifications]; } -(void)viewDidAppear:(BOOL)animated{ [super viewDidAppear:animated]; if (ipod.playbackState != MPMusicPlaybackStatePlaying) { [self presentModalViewController:self.ivc animated:YES]; }else{ [self showCurrentSongInfo]; } } -(IBAction)showInfoView{ [self presentModalViewController:self.ivc animated:YES]; } #pragma mark View Methods - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } - (void)viewDidUnload { // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (void)dealloc { [super dealloc]; } @end </code></pre> <p>Method call</p> <pre><code> [self presentModalViewController:self.ivc animated:YES]; </code></pre> <p>in ViewDidAppear causes EXC_BAD_ACCESS. </p> <p>I have tried debuging it with NSZombieEnabled but got only a stack call to main. The thing that gets me crazy is that if the same code is run from method playbackStateChanged it works fine. </p> <p>If any of you can help I wan't get bold as quick. Thanks. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload