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

themacster298

macrumors member
Original poster
Feb 20, 2011
55
0
Hi! I want to put a button that switches to another view. but I also want to put music when the button is pressed. but when i try it in the emulator it just crashes and takes you to the homescreen. Am I doing something wrong? Can a button have 2 actions? Or do I have to try it in a real iPhone?
 
Try this type of logic:

Code:
- (IBAction)myBtnPushed:(id)sender{
[self playMusic];
Right *DetailViewController = [[Right alloc] initWithNibName:@"Right" bundle:[NSBundle mainBundle]];
    [detailViewController.navigationController pushViewController:DetailViewController animated:YES];
}

- (void)playMusic{
 . . .
}
 
First of all, u never showed us what u tried, so how can we know if it crashes, and why would there be an simulator if u can't do anything with it.
So, problem is, you're probably doing something right.
The guy above me gave u perfect code for switching views, if u have a navcontroller in ur view.
Allthough u have to add the release.
And his declaring
Code:
Right *DetailViewController = [[Right alloc] initWithNibName:@"Right" bundle:[NSBundle mainBundle]];
    [detailViewController.navigationController pushViewController:DetailViewController animated:YES];
}
He forgot capitals

More like this
{
Code:
SecondViewController *secondVC = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:[NSBundle mainBundle]];
    [self.navigationController pushViewController:secondVC animated:YES];
[secondVC release];
}

Because using Capitals on ur properties is not the right way to go.
Second, add the release. and do the push on self. so it adds a retain.
Good luck.
The playing sound is about adding ur AVAudioPlayer and look up a tutorial about it, isn't that hard.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.