gpt4 book ai didi

objective-c - 为什么 waitUntilAllOperationsAreFinished 不在此代码中等待?

转载 作者:行者123 更新时间:2023-12-04 18:10:17 30 4
gpt4 key购买 nike

-(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.
}

即使self.operation还没有结束,执行点一直移动直到返回self.buttonIndex。

最佳答案

你怎么知道 self.operation 没有完成?您添加到其中的操作执行起来非常快:它只是将另一个操作添加到主队列。

你好像认为行

self.operation.suspended=true;

应该阻止正在进行的操作。但是来自 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.

您的操作已经在运行,因此不受影响。

为什么不告诉我们您实际想要实现的目标,我们可以建议实现目标的好方法。

关于objective-c - 为什么 waitUntilAllOperationsAreFinished 不在此代码中等待?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15360423/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com