2011-12-02 90 views

回答

2

您可以通過檢查出來uialertviewdelegate的文檔開始。

首先需要聲明類爲代表的UIAlertView中,然後實現來獲取用戶點擊按鈕的索引方法。

您可以使用這些方法來檢查用戶的選擇

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex 
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex 
+0

我知道那些方法。我只是不能讓它工作,以解僱模態視圖控制器。 – jaytrixz

+0

在這些你將需要調用'方法之一[自dismissModalViewControllerAnimated:YES];' –

+0

我能夠讓它工作中使用此代碼:' - (無效)alertView:(UIAlertView中*)actionSheet clickedButtonAtIndex:(NSInteger的)buttonIndex { 如果(buttonIndex == 0){ [自dismissModalViewControllerAnimated:YES]; } 其他 { 的NSLog(@ 「OK」); } }' – jaytrixz

0

使用警報視圖的委託方法

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    [self dismissModalViewControllerAnimated:YES]; 

} 

如果你有比OK按鈕更多,你需要提及按鈕指數,即

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 

    if(buttonIndex==0) 
    { 
    //Do something 
    } 

    if(buttonIndex==1) 
    { 
     [self dismissModalViewControllerAnimated:YES]; 
    } 
} 
0

如果您使用alertView關閉模式視圖控制器,

使用didDismissWithButtonIndex:(NSInteger的)buttonIndex代替clickedButtonAtIndex:(NSInteger的)buttonIndex

後者導致系統崩潰。

相關問題