3

我有一个 Iphone 应用程序,当我按下一个按钮时,它会显示一个警报视图来选择背景。无论用户选择哪个背景,都将作为音频剪辑的背景播放。但现在我需要在显示之前添加另一个警报此警报用于发出一些警告。之后我只需要弹出第二个。但我已经完成了在该视图控制器的 didappear 中选择警报并将其设置为 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;



}

在这是我的问题之前,我怎样才能包含另一个警报?

4

2 回答 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>{

}

希望这能满足您的需求!

于 2012-06-01T10:25:50.050 回答
0

您可以这样做,首先在 alertview 中显示警告消息,当用户在 alertview 中单击 OK 时,然后在 alertview 委托方法中编写代码以显示第二个 alertview,用户可以在其中选择背景。

于 2012-06-01T10:04:33.257 回答