I have an App that I am making thatis similar to Urbanspoon. I have a picker the spins and it is hooked up to an IBAction for a UIButton. I want a mp3 file to play once the button is pressed. I feel it will give the user more of an experience by doing this. I imported the AVFoundationFramework and the AudioToolBoxFramework and imported their .h into my main .m file
Here is my action.
- (IBAction)spinTheSpinner:(id)sender {
if ([sender isSelected]) {
[sender setImage:[UIImage imageNamed:@"GoldTapButton.png"] forState:UIControlStateNormal];
[sender setSelected:NO];
}
else {
[sender setImage:[UIImage imageNamed:@"PurpleTapButton.png"] forState:UIControlStateHighlighted];
[sender setSelected:YES];}
[picker1 selectRow:(arc4random() % [self pickerView:picker1 numberOfRowsInComponent:0]) inComponent:0 animated:YES];
}
Do i need to make a separate action for the same button or can i just add a block of code into this same action. I have the mp3 file is my resources folder so its in my project I just cant find where and what to do to make it happen.
Here is my .h as well just for good measure
#import <UIKit/UIKit.h>
#import<AVFoundation/AVAudioPlayer.h>
@interface ViewController : UIViewController
- (IBAction)spinTheSpinner:(id)sender;
@property (nonatomic, retain) NSMutableArray *picker1Data;
@end
also here is the top of my .m file
#import "ViewController.h"
#import "Twitter/Twitter.h"
#import "UIKit/UIKit.h"
#import"AVFoundation/AVAudioPlayer.h"
@interface ViewController ()
{
@private
UIPickerView *picker1;
}
@end
@implementation ViewController
Any help or suggestion or code would be a huge help in any way. I am running on a bit of a time schedule. THANKS SO
Yes you can just add the code into the same IBAction
method. You re not limited to th amount of code you can run in the method its currently linked to
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.