Skip to content

Instantly share code, notes, and snippets.

@farcaller
Created July 12, 2009 20:46
Show Gist options
  • Save farcaller/145795 to your computer and use it in GitHub Desktop.
Save farcaller/145795 to your computer and use it in GitHub Desktop.
- (void)onCatalog
{
RSSCatalogController *c = [[RSSCatalogController alloc] initWithNibName:@"RSSCatalogController" bundle:nil];
c.title = @"Catalog";
#ifdef USE_BLOCKS
UIActivityIndicatorView *scrollerView = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite] autorelease];
[scrollerView startAnimating];
UIBarButtonItem *scrollerItem = [[[UIBarButtonItem alloc] initWithCustomView:scrollerView] autorelease];
UIBarButtonItem *oldItem = [self.navigationItem.rightBarButtonItem retain];
[self.navigationItem setRightBarButtonItem:scrollerItem animated:YES];
NSOperationQueue *q = [[NSOperationQueue alloc] init];
[q pl_addOperationWithBlock:^{
// форкнули выполнение в поток
[c updateCategories]; // <--- медленная операция
[[NSThread mainThread] pl_performBlock: ^{
// вернулись в основной поток
[self.navigationItem setRightBarButtonItem:[oldItem autorelease] animated:YES];
[self.navigationController pushViewController:c animated:YES];
[c release];
[q autorelease];
}];
}];
#else
[c updateCategories];
[self.navigationController pushViewController:c animated:YES];
[c release];
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment