Created
January 26, 2011 08:19
-
-
Save marshluca/796412 to your computer and use it in GitHub Desktop.
使用NSInvocationOperation 处理多线程
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Load" | |
style:UIBarButtonItemStyleDone | |
target:self | |
action:@selector(loadData)]; | |
NSMutableArray *_array = [[NSMutableArray alloc] initWithCapacity:10000]; | |
self.array = _array; | |
[_array release]; | |
} | |
- (void) loadData { | |
NSOperationQueue *queue = [NSOperationQueue new]; | |
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self | |
selector:@selector(loadDataWithOperation) | |
object:nil]; | |
[queue addOperation:operation]; | |
[operation release]; | |
} | |
- (void) loadDataWithOperation { | |
NSURL *dataURL = [NSURL URLWithString:@"http://icodeblog.com/samples/nsoperation/data.plist"]; | |
NSArray *tmp_array = [NSArray arrayWithContentsOfURL:dataURL]; | |
for(NSString *str in tmp_array) { | |
[self.array addObject:str]; | |
} | |
[self.tableView reloadData]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment