繁体   English   中英

popViewController不适用于UIAlertView

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM