NickTang的专栏

iOS开发,不定期更新。

使用NSOperationQueue起线程

只有代码,解释以后加上:

#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

 

阅读更多
文章标签: interface thread object
个人分类: iOS-中级
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭