0
나는 Xcode에 초보자이며 xcode를 마스터 한 경험이 필요합니다. UIActionSheet를 사용하여 음악을 재생, 일시 중지, 중지하려고하지만 일시 중지 및 중지 버튼을 클릭해도 멈추지 않거나 재생 버튼 만 일시 중지합니다. 누군가 나를 도와 줄 수 있습니까? 내 코드는 다음과 같습니다.UIActionSheet로 음악 재생, 일시 정지, 정지
#import <AVFoundation/AVFoundation.h>
@interface MainViewController() <UIActionSheetDelegate,AVAudioPlayerDelegate>
@property(nonatomic,retain)AVAudioPlayer *playAudio;
@end
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *buttonTitle =[actionSheet buttonTitleAtIndex:buttonIndex];
NSURL *url =[NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/MusicName.mp3",[[NSBundle mainBundle] resourcePath]]];
NSError *error;
self.playAudio=[[AVAudioPlayer alloc]initWithContentsOfURL:url error:&error];
if (buttonIndex==0) {
[self.playAudio play];
}
if ([buttonTitle isEqualToString:@"Pause"]) {
[self.playAudio pause];
}
if (buttonIndex==2) {
[self.playAudio stop];
}
}
- (IBAction)Music:(id)sender {
UIActionSheet *musicSheet =[[UIActionSheet alloc]initWithTitle:@"Choose" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Play",@"Pause",@"Stop", nil];
[musicSheet showInView:self.view];
}
. 나는 베트남 사람이므로 내 영어 실력으로는 내가하는 말을 이해하기 어렵게 만들 수 있습니다. 시간 내 주셔서 감사합니다 . 귀하의 회신을 기다리고 있습니다.
TKS 내가 당신에게 나중에 – Triet
말해주지 내가 스위치 statement.Do을 사용하는 경우 ... 아니 아직도 내가 위양을 설정하는 데에도 작동하지 각 buttonIndex? switch 문 전에 대리자를 설정하려고했지만 여전히 작동하지 않습니다. – Triet
왜 UIButton에서 작동합니까 ????? UIActionSheet 버튼이 아닙니까? – Triet