【问题标题】:alertView didDismissWithButtonIndex never calledalertView didDismissWithButtonIndex 从未调用过
【发布时间】:2013-07-08 21:32:50
【问题描述】:

如有不妥之处请见谅……第一次发帖。

我已经看到了一些与此类似的问题,但没有一个具有相同的问题。我正在运行 IOS 6.1 和 Xcode 4.6。问题是 didDismiss 永远不会被调用,只会被调用。我的代码与日志输出一起在下面。有什么想法吗?

#import "MenkLabUIAlertTestViewController.h"

@interface MenkLabUIAlertTestViewController ()

@end

@implementation MenkLabUIAlertTestViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.


}
- (IBAction)test:(id)sender {
    UIAlertView *av  = [[UIAlertView alloc] initWithTitle:@"Encrypting File(s)" message:@"Please wait..." delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
    //    UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    [av show];
    [av dismissWithClickedButtonIndex:-1 animated:YES];
}

- (void) alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex {
    NSLog(@"willDISMIS");
}

- (void) alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
    NSLog(@"didDISMIS");
   }


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

日志输出:

2013-07-08 17:27:04.055 testUIAlertView[10534:11303] willDISMIS

这只是一个测试应用程序,但是,它与我当前应用程序中存在的完全相同的问题。

提前致谢。整天都在为此绞尽脑汁!

【问题讨论】:

标签: iphone ios objective-c uialertview ios6.1


【解决方案1】:

我认为这是您正在显示的事实,然后立即以相同的方法关闭警报视图 - 您永远不会在真正的应用程序中真正做到这一点。如果您为警报视图创建一个属性,然后像下面那样进行测试,它可以正常工作:

- (IBAction)test:(id)sender {
    self.av  = [[UIAlertView alloc] initWithTitle:@"Encrypting File(s)" message:@"Please wait..." delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
    [self.av show];
    [self performSelector:@selector(dismissAlertView) withObject:nil afterDelay:1];
}


-(void)dismissAlertView {
    [self.av dismissWithClickedButtonIndex:-1 animated:YES];
}

- (void) alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex {
    NSLog(@"willDISMIS");
}

- (void) alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
    NSLog(@"didDISMIS");
}

【讨论】:

    【解决方案2】:

    我遇到了类似的问题,作为一种解决方法,我们添加了一个选择器方法,该方法在一些延迟后运行,这将触发警报视图的解除。如果我们要求警报在显示后立即关闭,我不确定为什么它不起作用。希望对您有所帮助。

    【讨论】:

      【解决方案3】:

      我也遇到了这个问题。对我来说,这与尝试使用 -1 上的按钮索引以编程方式解除它有关。由于其他原因,我们最终走上了一条不同的道路。但是,操作表上有一个取消按钮索引,您可以尝试使用它来调用它。

      【讨论】:

        【解决方案4】:

        我曾经遇到过这个问题。对我来说,问题是由动画之间的碰撞引起的。 didDismiss 选择器在动画结束时被调用。如果在willDismissdidDismiss 之间启动另一个动画,则在极少数情况下不必调用didDismiss

        另请注意,如果您尝试在警报完全显示之前将其关闭,它永远不会正常工作。

        【讨论】:

          【解决方案5】:

          我已经添加了。这解决了我的问题。

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

          【讨论】:

            猜你喜欢
            • 2011-01-27
            • 1970-01-01
            • 2020-04-26
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2016-02-21
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多