views:

237

answers:

1

Hello

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.

+1  A: 

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.
}
KennyTM
This is not working: CFRunLoopRunInMode(UITrackingRunLoopMode, 0.1, true);I'm going o try the other approach ...thanks,r.
mongeta
@mongeta: Probably you need to run in `kCFRunLoopModeDefault` mode instead of `UITrackingRunLoopMode`. The other route is better though.
KennyTM
Thanks, finally a good combination of both solutions solved my problem. :-)
mongeta