Calling [self presentViewController]
on an instance of UIAlertController
loads the alert immediately. Is there a way to delay its presentation?
[self presentViewController:alert animated:YES completion:nil];
Calling [self presentViewController]
on an instance of UIAlertController
loads the alert immediately. Is there a way to delay its presentation?
[self presentViewController:alert animated:YES completion:nil];
You can use GCD or performSelector:withObject:afterDelay:
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self presentViewController:alert animated:YES completion:nil];
});
You can also create a local variable and then call present at the right time that you want. Depends on your use-case, one of these three should help you on delaying and showing the alert controller at the right moment.
EDIT: Here's the Swift version of this answer:
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
self.present(alert, animated: true)
}
You can also check this answer
If you are waiting for something to download or something, you may also consider using a block that is called (and presents the view controller) once the task is complete. If you do this you should also use some sort of loading animation.