2

在我正在开发的应用程序中,我展示了一个UIAlertView. 使用NSTimerI 删除调用方法的警报removeFromSuperView。警报被删除,但随后任何控件都适用于当前视图。任何人都可以帮助我如何解决它?这是我显示警报的代码:

UIAlertView *alert=[UIAlertView alloc]initWithTitle:@"A" message:@"B" delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
        [alert show];
        [alert release];
[NSTimer scheduledTimerWithTimeInterval:4.0 target:self selector:@selector(removeAlert:) userInfo:nil repeats:NO];

以及定时器调用的方法:

-(void)removeAlert:(id)sender
{
    [alert_View removeFromSuperview];
}
4

3 回答 3

12

请尝试以下一行代码

[alert dismissWithClickedButtonIndex:0 animated:YES];

你的问题会解决

于 2013-06-04T10:29:00.363 回答
2

通过在 .h 文件中启动它来创建您的即时全局警报

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController<UIAlertViewDelegate>
{
    UIAlertView *alert;
}

然后在 .m 文件中

//here use that instant variable alert
alert=[[UIAlertView alloc]initWithTitle:@"A" message:@"B" delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
    [alert show];
    [NSTimer scheduledTimerWithTimeInterval:4.0 target:self selector:@selector(removeAlert:) userInfo:nil repeats:NO];

-(void)removeAlert:(id)sender
{
    NSLog(@"hi dilip");
    [alert dismissWithClickedButtonIndex:0 animated:YES];
}
于 2013-06-04T10:42:38.147 回答
0

使用[alert dismissWithClickedButtonIndex:-1 animated:YES];而不是[alert removeFromSuperView];)它是一个模态视图,所以你必须解雇而不只是删除:)

于 2013-06-04T10:28:42.753 回答