一个视图中如何添加多个弹窗?

3

我有一个iPhone应用程序,当我按下一个按钮时,它会显示一个警告框来选择背景。无论用户选择哪种背景,都将作为音频剪辑的背景播放。但现在我需要在显示此警告之前添加另一个警告,以便发出一些警告。之后只需要弹出第二个。但是我在那个视图控制器的didappear中完成了选择警报,并将其设置为Uialertview delegate。在按钮操作上,我正在执行不同的操作。有人可以帮助我实现这个吗?

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;



}

在这之前加入另一个提示框应该怎么做?

2个回答

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>{

}

希望这样可以满足你的需求!

嗨,我明确指出我需要在选择背景消息之前提供一个简单的警告消息。你现在所做的是在选择背景后去另一个消息。那不是我想要的,对不起。 - hacker
但是,你可以切换警告视图!使用“al1”作为警告,当用户按下“al1”的“确定”按钮时,打开“al2”以选择背景音乐。 - jaym

0
你可以这样做,首先在警告视图中显示警告消息,当用户在警告视图中点击“确定”后,在警告视图的委托方法中编写代码以显示第二个警告视图,用户可以选择背景。

现在我正在处理带有3个按钮的委托中的选择警报。我该如何将这些操作包含到警告的“确定”按钮操作中? - hacker

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接