只有代码,解释以后加上:
#import <UIKit/UIKit.h>
@interface tOQViewController : UIViewController {
NSOperationQueue *myOQ;
}
-(void)doSomething;
@end
实现文件如下:
#import "tOQViewController.h"
@implementation tOQViewController
-(void)doSomething
{
NSLog(@"in thread");
}
- (void)dealloc
{
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
myOQ = [[NSOperationQueue alloc] init];
[myOQ setMaxConcurrentOperationCount:1];
NSInvocationOperation *op = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(doSomething) object:nil];
[myOQ addOperation:op];
[op release];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end