2012-08-16 30 views
-1

我遇到了AlertView問題。我正在嘗試使用UIAlertView,點擊確定後它會返回到前一個屏幕,但似乎沒有任何建議?popViewController不能與UIAlertView一起使用

if (xGPSCoordinate==0 && yGPSCoordinate == 0) { 

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" 
                message:@"Failed to load the to get your current location" 
                delegate:self 
              cancelButtonTitle:@"Ok" 
              otherButtonTitles:nil, nil]; 
    [alert show]; 
    [alert release]; 

    return; 
    [self.navigationController popViewControllerAnimated:YES]; 
} 

if (xGPSCoordinate==0 && yGPSCoordinate == 0) { 

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"iPoly" 
                message:@"Failed to load the to get your current location" 
                delegate:self 
              cancelButtonTitle:@"Ok" 
              otherButtonTitles:nil, nil]; 
    [alert show]; 
    [alert release]; 
    [self.navigationController popViewControllerAnimated:YES]; 
    return; 

} 

都不起作用

+0

當你進入這個觀點,你用推視圖控制器或presentModalViewController? – Neo 2012-08-16 08:59:55

+0

我用pushViewController – sihao 2012-08-16 09:03:46

+0

刪除標籤:Xcode無關緊要,並不限於iPhone – vikingosegundo 2012-08-16 09:04:10

回答

3

爲此,你已經使用UIAlertView的委託方法。在@interface<UIAlertViewDelegate>

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

第一次使用此然後設置委託,self.yourAlertView.delegate=self;

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

     if(buttonIndex==0)//first button which should be the OK button 
     { 

       [self.navigationController popViewControllerAnimated:YES]; 

     } 

} 
+0

? – sihao 2012-08-16 08:58:53

+0

@ user1495988或者你可以在你創建'UIAlertview'的地方設置它,有一個委託選項。在你的情況下,它已經被設置爲「自我」,所以不應該是一個問題。 – iNoob 2012-08-16 09:00:19

+0

哦,好吧,我明白了。好的,謝謝你的幫助:) – sihao 2012-08-16 09:05:40

0

您只需要實現UIAlerView委託方法。

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

寫你對流行音樂的代碼之前的控制器here.You可以點擊的按鈕指數,你可以use.Don't的基礎上,順應UIAlertViewDelegate接口。

1

使用UIAlertView的委託方法,請參閱由iNoob給出的答案。如果你在「返回」之後寫了任何東西,這是沒有意義的。聲明作爲下面的代碼「返回」;語句永遠不會被執行。

是指對UIAlertView中代表http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIAlertViewDelegate_Protocol/UIAlertViewDelegate/UIAlertViewDelegate.html

或警報視圖一個簡單的教程更詳細的蘋果開發者聯繫 http://mobile.tutsplus.com/tutorials/iphone/uialertview/

相關問題