-(NSInteger) buttonIndexWithMessage:(NSString *) title andArrayOfOptions:(NSArray *) options
{
self.operation=[NSOperationQueue new];
[self.operation addOperationWithBlock:^{
[[NSOperationQueue mainQueue]addOperationWithBlock:^{
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:title
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
for (NSString * strOption in options) {
[actionSheet addButtonWithTitle:strOption];
}
[actionSheet showInView:[BGMDApplicationsPointers window]];
}];
self.operation.suspended=true; //Okay make t
}];
[self.operation waitUntilAllOperationsAreFinished];//Don't get out of the function till user act.
//Wait till delegate is called.
return self.buttonIndex;//I want to return buttonIndex here.
}
The execution point keeps moving till return self.buttonIndex even though self.operation has not finished.
How do you know that self.operation has not finished? The operation you add to it is very fast to execute: it just adds another operation to the main queue.
You seem to think that the line
self.operation.suspended=true;
should block the ongoing operation. But from the documentation:
This method suspends or resumes the execution of operations. Suspending a queue prevents that queue from starting additional operations. In other words, operations that are in the queue (or added to the queue later) and are not yet executing are prevented from starting until the queue is resumed. Suspending a queue does not stop operations that are already running.
Your operation is already running, so is not affected.
Why don't you tell us what you are actually trying to achieve, and we can suggest good ways how to achieve that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With