定時消失的Alert彈窗

在公共類裏面寫以下兩個類方法就能夠了,只須要把第一個類方法公佈出來:orm

代碼以下:blog

#pragma mark --- 定時彈窗 ---
+ (void)showAlertViewWithTitle:(NSString *)title message:(NSString *)message afterDelay:(NSTimeInterval)delay {
    
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
    [alert show];
    [self performSelector:@selector(dimissAlert:) withObject:alert afterDelay:delay];
}

+ (void)dimissAlert:(UIAlertView *)alert {
    if(alert)     {
        [alert dismissWithClickedButtonIndex:[alert cancelButtonIndex] animated:YES];
    }
}
相關文章
相關標籤/搜索