ios – UIAlertController仅在2秒后解除

ios – UIAlertController仅在2秒后解除,第1张

概述我希望在呈现后立即解雇,但只能在2秒后才能解决.这该怎么做? 这是我在UILabel上从UITapGestureRecognizer调用的方法. - (IBAction)labelTaped:(UITapGestureRecognizer *)sender { if (sender.state == UIGestureRecognizerStateEnded) { CGRect fra 我希望在呈现后立即解雇,但只能在2秒后才能解决.这该怎么做?

这是我在UILabel上从UITapGestureRecognizer调用的方法.

- (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:^{        //    }];}
解决方法 最简单的是这样的吗?

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Alert" message:@"message dismiss in 2 seconds" preferredStyle:UIAlertControllerStyleAlert];[self presentVIEwController:alertController animated:YES completion:nil];dispatch_after(dispatch_time(disPATCH_TIME_Now,(int64_t)(2.0 * NSEC_PER_SEC)),dispatch_get_main_queue(),^{    [alertController dismissVIEwControllerAnimated:YES completion:^{        // do something ?    }];});

或者你的意思是你还想阻止用户在触发2秒之前点击取消按钮?

总结

以上是内存溢出为你收集整理的ios – UIAlertController仅在2秒后解除全部内容,希望文章能够帮你解决ios – UIAlertController仅在2秒后解除所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1082412.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存