自动消失对话框

来源:互联网 发布:c语言实型数据 编辑:程序博客网 时间:2024/04/26 07:39

- (void)showAutoDialogWithTitle:(NSString *)title message:(NSString *)message

{

    UIAlertView *alert = [[UIAlertViewalloc] initWithTitle:title

                                                    message:message

                                                    delegate:nil

                                                    cancelButtonTitle:nil 

                                                    otherButtonTitles:nil];

    [alert show];

                          

                          

    [NSTimer scheduledTimerWithTimeInterval:1.0f

                                    target:self

                                    selector:@selector(dismissAlert:)

                                    userInfo:[NSDictionarydictionaryWithObjectsAndKeys:alert, @"autoalert" ,nil//如果不用传递参数,那么可以将此项设置为nil.  

                                    repeats:NO];  

                          

    NSLog(@"release alert");  

    [alert release];

}


-(void) dismissAlert:(NSTimer *)timer{

    

    NSLog(@"release timer");

    UIAlertView *alert = [[timeruserInfoobjectForKey:@"autoalert"];

    [alert dismissWithClickedButtonIndex:0animated:YES];

    [_timerinvalidate];

    _timer = nil;

}

原创粉丝点击