ViewDidAppearでpresentModalViewControllerをロードするとEXC_BAD_ACCESSを引き起こし
-
21-09-2019 - |
質問
Follwoing ViewControllerClassで、私はEXC_BAD_ACCESSがViewDidAppear方法でpresentModalViewControllerを呼び出そうとしたときに取得します。
#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
メソッドの呼び出し
[self presentModalViewController:self.ivc animated:YES];
ViewDidAppearではEXC_BAD_ACCESSを引き起こします。
私はNSZombieEnabledでそれをデバッグの試みましたが、メインにのみスタックコールを持っています。 私はクレイジー取得する事がメソッドから実行されているのと同じコードがplaybackStateChanged場合には罰金を動作することです。
あなたのいずれかが、私は速いのように大胆取得wan'tを助けることができる場合。ありがとうございました。
解決
私は最終的に仕事にそれを作りました!しかし、私はそれだけで簡単な修正だと思います。
だから、私はIVCは、私はpresentModalViewController
への呼び出しを遅らせることが必要に表示できるようにすることことが判明しました[self performSelector:@selector(showWaitingMessageView:) withObject:self.ivc afterDelay:1];
それはそれです。できます。
これが助けた理由私はあなた達人の一つは、それについての詳細を知っているそうなら、私を啓発してくださいます。
、知りません所属していません StackOverflow