Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

nickculbertson

macrumors regular
Original poster
Nov 19, 2010
226
0
Nashville, TN
Hi,
I have a view based application in which the viewDidLoad method of my initial view controller (FirstViewController) is being called while the other view is being shown. The reason this is an issue is because I am playing music in the viewDidLoad of my first view and it reloads randomly as I'm in my second view (GameViewController).

Code:
// in my FirstViewController.m


-(IBAction) press1{ 
	[theAudio stop];
	GameViewController *views = [[GameViewController alloc] initWithNibName:Nil bundle:nil];
	[self presentModalViewController:views animated:YES];
}

- (void)viewDidLoad {
	NSString *path = [[NSBundle mainBundle] pathForResource:@"Song1" ofType:@"wav"];
	theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
	theAudio.delegate = self;
	[theAudio play];
}

I've tried playing the sound on launch from the app delegate but I want to be able to control the AVAudioPlayer variable from my FirstViewController.h since it is playing the first track of a playlist.

Any thoughts?

Thanks,
Nick

Edit: I put the code in - (void) awakeFromNib { } and that did the trick
 
Last edited:
Why would your FirstViewController randomly be loading its view when it is not preparing to display? Why would something that happens when GameViewController is visible cause FirstViewController to need to load its view?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.