Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to dismiss an no button UIalertView after some time?

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"tittle"
               message:@""
                 delegate:self
              cancelButtonTitle:@""
              otherButtonTitles:nil];
  [alertView show];
  [alertView release];

i want to dimiss the alerview after it's showing for some time,but when the alertview has no button,it doesn't work if i invoked -dismissWithClickedButtonIndex:animated: methodand-performSelector:withObject:afterDelay: is there any other way to dismiss it ? thanks for any ideas!

like image 542
ben Avatar asked Nov 16 '10 09:11

ben


2 Answers

-(void)xx  {
     [self performSelector:@selector(dismissAlertView:) withObject:alertView afterDelay:2];
}
-(void)dismissAlertView:(UIAlertView *)alertView{
    [alertView dismissWithClickedButtonIndex:0 animated:YES];
}

that's it.i fix it

like image 141
ben Avatar answered Oct 20 '22 18:10

ben


Use 10 seconds delays to dismiss

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:@"" preferredStyle:UIAlertControllerStyleAlert];
[self presentViewController:alertController animated:YES completion:nil];

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    [alertController dismissViewControllerAnimated:YES completion:^{
        p\Perform Action after dismiss alertViewController
    }];
});
like image 30
Sahila Mirajkar Avatar answered Oct 20 '22 17:10

Sahila Mirajkar