Opening a UIActivityIndicatorView after a UIActionSheet
-
19-09-2019 - |
Question
I have some destructive operations that need confirmation, and I'm using the UIActionSheet.
Inside the clickedButtonAtIndex I fire some lenghtly operations that need a UIActivityIndicatorView.
The problem is that I can't see the UIActivityIndicatorView until the UIActionSheet has closed, and this happens when the operation has finished.
Can I force to close the UIActionSheet even if the user has pressed some buttons and their clickedButtonAtIndex delegate has been fired ?
In pseudo code:
- User wants to do some destructive operation
- Request confirmation with a UIActionSheet
- The user says YES
- Delegate clickedButtonAtIndex fires and invokes a lenghtly operation
- This operation, the first thing that does is opening a UIActivityIndicatorView but because the UIActionSheet is active, I can't see until the end ...
thanks,
r.
Solution
You can call
CFRunLoopRunInMode(UITrackingRunLoopMode, 0.1, true);
to let the UI elements refresh before your lengthy calculation begins. Alternatively, you can use
-(void)doLengthyOperation {
show_activity_indicator_view();
[self performSelector:@selector(doRealLengthyOperation) withObject:nil afterDelay:0.1];
}
-(void)doRealLengthyOperation {
// do the real lengthy operations.
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow