我有一个Iphone应用程序,当我按下一个按钮时,它会显示一个警报视图来选择背景。那个背景用户正在选择将作为音频剪辑的背景播放。但是现在我需要在之前添加另一个警报我正在显示这个警告以提供一些警告。之后只有我需要弹出第二个。但是我在那个视图控制器的出现时做了那个选择警报并将其设置为Uialertview委托。并且我正在做的按钮动作不同的行动。任何人都可以帮我实现这个目标吗?
proAlertView *loginav1=[[proAlertView alloc] initWithTitle:@"title" message:@"Choose a Background to play with this program?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Field",@"Beach", @"Stars",nil];
[loginav1 setBackgroundColor:[UIColor colorWithRed:0.129 green:0.129 blue:0.129 alpha:1.0] withStrokeColor:[UIColor colorWithHue:0.625 saturation:0.0 brightness:0.8 alpha:0.8]];
[loginav1 show];
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
// the user clicked one of the OK/Cancel buttons
if (buttonIndex == 0)
{
//[self play];
//moviePlayer.scalingMode=MPMovieScalingModeAspectFill;
if(actionSheet.tag==123)
{
[self backButtonPressed];
}
}
else if (buttonIndex == 1)
{
videoFile = [[NSBundle mainBundle] pathForResource:@"video-track" ofType:@"mp4"];
[self play];
moviePlayer.scalingMode=MPMovieScalingModeAspectFill;
}
在我的问题出现之前,我怎么能包含其他警报呢?
答案 0 :(得分:4)
初始化第一个Alertview
UIAlertView *al1 = [[UIAlertView alloc] initWithTitle:@"Warning!" message:@"Warning Msg!!!" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
al1.tag=1;
al1.delegate=self;
[al1 show];
实施委托方法
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if(alertView.tag==1){
// implement button events for first Alertview
if(buttonIndex==1){
//First button clicked of first Alertview
UIAlertView *al2 = [[UIAlertView alloc] initWithTitle:@"Choose BG" message:@"Choose BG?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"1",@"2",@"3", nil];
al2.tag=2;
al2.delegate=self;
[al2 show];
}
}
if(alertView.tag==2){
// implement button events for second Alertview
if(buttonIndex==1){
// First button clicked second Alertview.
}
}
}
控制器类标题
@interface ViewController : UIViewController<UIAlertViewDelegate>{
}
希望这能满足您的需求!
答案 1 :(得分:0)
您可以这样做,首先在alertview中显示警告消息,当用户在alertview中单击OK然后在alertview委托方法中编写代码以显示第二个alertview,用户可以在其中选择背景。