Created
April 20, 2011 12:59
-
-
Save simme/931269 to your computer and use it in GitHub Desktop.
Loading with NSOperation instead
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
| - (id)initWithCoder:(NSCoder *)aDecoder | |
| { | |
| if ((self = [super initWithCoder:aDecoder])) { | |
| [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES]; | |
| // Load the data | |
| NSOperationQueue *queue = [[NSOperationQueue alloc] init]; | |
| NSOperationQueue *main = [NSOperationQueue mainQueue]; | |
| NSBlockOperation *fetchStreamOperation = [[NSBlockOperation alloc] init]; | |
| [fetchStreamOperation addExecutionBlock:^{ | |
| NSLog(@"Getting data"); | |
| NSURL *publicTimeline = [NSURL URLWithString:@"https://api.twitter.com/1/statuses/public_timeline.json"]; | |
| NSError *error = nil; | |
| NSData *tweetData = [NSData dataWithContentsOfURL:publicTimeline options:0 error:&error]; | |
| _tweets = [[tweetData objectFromJSONData] retain]; | |
| [main addOperationWithBlock:^{ | |
| [self.tableView reloadData]; | |
| [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; | |
| }]; | |
| //[self performSelectorOnMainThread:@selector(reloadData:) withObject:tweets waitUntilDone:NO]; | |
| }]; | |
| [queue addOperation:fetchStreamOperation]; | |
| [queue release]; | |
| self.title = @"Tweetoramah"; | |
| } | |
| return self; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment