只有代码,解释以后加上:
#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
本文深入探讨了iOS开发中的Swift编程语言,分享了实际项目中使用的高效编码实践和最佳编程习惯,帮助开发者提高开发效率并创建高质量的应用程序。
7万+

被折叠的 条评论
为什么被折叠?



