![](/img/trans.png)
[英]popViewController doesn't work in UITableViewController
[英]popViewController doesn't work with UIAlertView
我有AlertView問題。 我正在嘗試使用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;
}
兩者都不起作用
為此,您必須使用UIAlertView
的委托方法。
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
首先在@interface
<UIAlertViewDelegate>
然后設置委托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];
}
}
使用UIAlertView的委托方法,請參閱iNoob給出的答案。 如果在“返回”之后寫任何內容,這是沒有道理的; 聲明為“返回”下面的代碼; 語句將永遠不會執行。
有關UIAlertView委托的更多詳細信息,請參閱Apple開發人員鏈接http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIAlertViewDelegate_Protocol/UIAlertViewDelegate/UIAlertViewDelegate.html
或有關警報視圖的簡單教程http://mobile.tutsplus.com/tutorials/iphone/uialertview/
您只需要實現UIAlerView委托方法。
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{}
在此處將Pop的代碼編寫到上一個Controller。您可以單擊按鈕的索引並在此基礎上使用。不要將UIAlertViewDelegate設置為Interface。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.