Voglio chiudere immediatamente, dopo averlo presentato, ma posso farlo solo dopo 2 secondi. Come fare questo?UIAlertController respingere solo dopo 2 secondi
Ecco il mio metodo che viene chiamato da UITapGestureRecognizer su un UILabel.
- (IBAction)labelTaped:(UITapGestureRecognizer *)sender {
if (sender.state == UIGestureRecognizerStateEnded) {
CGRect frame = CGRectNull;
NSString *message = nil;
// ...
// some code
/// ...
if (message) {
// show info alert
__weak __typeof(self)weakSelf = self;
UIAlertController* alert = [UIAlertController alertControllerWithTitle:nil
message:message
preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"alert_ok", @" - ")
style:UIAlertActionStyleCancel
handler:^(UIAlertAction * action) {
if ([weakSelf.dismissAlertTimer isValid]) {
[weakSelf.dismissAlertTimer invalidate];
}
}];
[alert addAction:cancelAction];
UIPopoverPresentationController *popoverController = alert.popoverPresentationController;
popoverController.sourceRect = frame;
popoverController.sourceView = sender.view;
[self.mainController presentViewController:alert animated:YES completion:^{
if ([weakSelf.dismissAlertTimer isValid]) {
[weakSelf.dismissAlertTimer invalidate];
}
weakSelf.dismissAlertTimer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:weakSelf selector:@selector(dismissAlertController) userInfo:nil repeats:NO];
}];
}
}
}
- (void)dismissAlertController {
[self.mainController dismissViewControllerAnimated:YES completion:^{
//
}];
}