-1

我在使用 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;

}   

两者都不起作用

4

3 回答 3

3

为此,您必须使用UIAlertView's 委托方法。

- (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];

       }

 }
于 2012-08-16T08:55:17.287 回答
1

使用 UIAlertView 的委托方法,见 iNoob 给出的答案。如果在“返回”之后写任何东西是没有意义的;声明为“return;”下面的代码 语句永远不会被执行。

有关 UIAlertView 委托的更多详细信息,请参阅苹果开发人员链接http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIAlertViewDelegate_Protocol/UIAlertViewDelegate/UIAlertViewDelegate.html

或警报视图的简单教程 http://mobile.tutsplus.com/tutorials/iphone/uialertview/

于 2012-08-16T09:04:32.867 回答
0

您只需要实现 UIAlerView 委托方法。

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

在这里将 Pop 的代码写到上一个控制器。您可以单击按钮索引并在此基础上使用。不要将 UIAlertViewDelegate 与接口一致。

于 2012-08-16T09:00:25.893 回答