【发布时间】:2010-10-21 12:14:07
【问题描述】:
我之前在 iPhone OS 3.0 中的 iPhone 应用程序中使用过 NSOperationQueue,但现在在 iOS 4.0 中代码无法正常工作。它只在所有后续调用中正常运行一次,它不起作用。 iOS 4.0 中的 NSOperationQueue 有变化吗?
相关代码如下:
- (void) starteffectFunction {
NSOperationQueue *queue = [NSOperationQueue new];
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(starteffectProcessing)
object:nil];
[queue addOperation:operation];
[operation release];
[queue release];
[spinner startAnimating];
}
-(void) starteffectProcessing{
some code executes. code snippet. A
......
this code is note supposed to execute before A completes. But this executes before A.
}
【问题讨论】:
-
请解释“不起作用”。它是崩溃还是什么都不做,是否收到警告、错误消息和其他提示?
-
不,没有警告、错误和崩溃。我正在做的是创建一个 nsoperationqueue 并执行一个函数。我会展示一个微调器,直到这个 nsoperation 完成。这第一次工作正常,但第二次。应该在 nsoperationqueue 完成后执行的代码在 nsoperation 完成之前执行。
-
给我们一些代码 sn-p 怎么样?
-
好的。我已经在我的问题中发布了代码。我认为我的假设是错误的,即 nsoperationqueue 存在问题。有什么东西可以确保在第 1 行完成执行之前,第 2 行执行不会开始。顺便说一句,我在第一部分进行了一些图像编辑。
标签: iphone nsoperation nsoperationqueue