2012-06-01 60 views
3

我有一個iPhone應用程序中,當我按下一個按鈕,它顯示了一個alertview到選擇的background.whichever背景用戶艇員選拔將播放的音頻clips.But的背景下,現在我必須先添加另一個警報我表示給予一定warning.after,只有我需要彈出第二one.but我做,在該視圖 - 控制的didappear艇員選拔警報,並將其設置爲UIAlertView中按鈕的動作我在做不同delegate.and此警報行動。有人能幫我實現這個目標嗎?單個視圖中有多個alertview?

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

初始化第一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>{ 

} 

希望這將滿足您的需求!

+0

您好我很清楚地說明我需要給一個簡單的我BG的艇員選拔之前警告消息msg.What你[R做的是chosng BG烏爾去了另一個msg.that後不是我想要對不起人 – hacker

+0

但是,人類可以切換該警報的意見!使用「al1」進行警告,當用戶按下「al1」的「確定」按鈕時,打開「al2」選擇BG聲音。 – jaym

+0

我已更新我的回答 – jaym

0

你可以這樣做,在alertview第一顯示警告信息,當用戶單擊OK alertview然後alertview委託方法寫代碼來顯示第二alertview這裏用戶可以選擇背景。

+0

現在我正在處理代理中的選擇提醒,帶有3個按鈕。如何將這些操作包含到ok按鈕中的警告作用 – hacker

+0

可以看到我的編輯 – hacker