0

ios3上这些操作的等价物是什么

[NSOperationQueue mainQueue];
[NSOperationQueue currentQueue];
4

2 回答 2

1

+currentQueue 确实没有等价物。对于 +mainQueue 你会打电话

- (void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)arg waitUntilDone:(BOOL)wait

使用包含需要在主线程上完成的工作的方法。

于 2011-05-12T08:19:18.353 回答
0

除了自己滚动之外,没有其他选择。

像这样的东西可能会起作用:(未经测试)

@interface NSOperationQueue(MainQueueAdditions) 

+ (NSOperationQueue *) mainQueue;

@end

@implementation NSOperationQueue(MainQueueAdditions)

+ (NSOperationQueue *) mainQueue {
  static NSOperationQueue *queue = nil;
  if(queue == nil) queue = [[NSMainOperationQueue alloc] init];
  return queue;
}
@end

@interface NSMainOperationQueue : NSOperationQueue {}
@end

@implementation NSMainOperationQueue

- (void) addOperation:(NSOperation *) operation {
  [self queueOperationInternal:operation];
}

- (void) addOperationWithBlock:(void (^)(void))block {
   [self queueOperationInternal:[NSBlockOperation blockOperationWithBlock:block]];
}


- (void) queueOperationInternal:(NSOperation *) operation {
   [[NSRunLoop mainRunLoop] performSelector:@selector(start) target:operation argument:nil order:-[operation queuePriority] modes:[NSArray arrayWithObject:NSRunLoopCommonModes]]; 
}

@end
于 2011-05-12T08:38:50.377 回答