簡體   English   中英

alertView didDismissWithButtonIndex從未調用過

[英]alertView didDismissWithButtonIndex never called

如果有些事情沒有發布正確,請原諒我...第一次發帖。

我已經看到了幾個與此類似的問題,但沒有一個問題存在同樣的問題。 我正在運行IOS 6.1和Xcode 4.6。 問題是didDismiss永遠不會被調用,只有willDismiss。 我的代碼與日志輸出一起在下面。 有任何想法嗎?

#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

這只是一個測試應用程序,但是,它與我當前的應用程序中存在的完全相同的問題。

提前致謝。 這一整天都在絞盡腦汁!

我認為這是你正在展示的事實,然后立即以相同的方法解雇警報視圖 - 你真的永遠不會在真正的應用程序中這樣做。 如果您為警報視圖創建一個屬性,然后執行如下所示的測試,它可以正常工作:

- (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");
}

我遇到了類似的問題,作為一種解決方法,我們添加了一個選擇器方法,該方法在一段延遲后運行,而不會觸發警報視圖的解雇。 如果我們要求警報在顯示后立即解雇,我不確定為什么它不起作用。 希望能幫助到你。

我也遇到了這個問題。 對我而言,這與嘗試以-1的按鈕索引以編程方式解除它有關。 出於其他原因,我們最終走上了另一條道路。 但是,操作表上有一個取消按鈕索引,您可以嘗試使用該索引。

我遇到過這個問題一次。 對我來說,問題是由動畫之間的碰撞引起的。 動畫結束時調用didDismiss選擇器。 如果在willDismissdidDismiss之間啟動另一個動畫,那么在極少數情況下不必調用didDismiss

另請注意,如果您在完全顯示警報之前嘗試關閉警報,它將無法正常工作。

我已經添加了。 這解決了我的問題。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM