Skip to content

Instantly share code, notes, and snippets.

@roalcantara
Created June 14, 2012 07:30
Show Gist options
  • Save roalcantara/2928732 to your computer and use it in GitHub Desktop.
Save roalcantara/2928732 to your computer and use it in GitHub Desktop.
Objective C Block Sample
typedef void (^Completion)(void);//block definition
@interface MyUITableViewController : UITableViewController
@property (nonatomic, copy) NSString* myTitle;
@property (readwrite, copy) Completion completion;
-(MyUITableViewController *)initWithTitle: (NSString *) _myTitle
completion: (Completion) _completion;
-(void)back;
@end
@implementation MyUITableViewController
@synthesize myTitle, completion;
-(MyUITableViewController *)initWithTitle: (NSString *) _myTitle
completion: (Completion) _completion
{
self = [super initWithNibName: @"MyUITableViewController"
bundle: Nil];
if (self) {
self.myTitle = _myTitle;
self.completion = _completion;
}
return self;
}
-(void)back
{
[self dismissViewControllerAnimated: YES
completion: self.completion];
}
@end
@implementation UsingObjectiveCBlockTest
-(void)usingBlockTest
{
MyUITableViewController* controller = [[MyUITableViewController alloc]
initWithTitle: @"Block sample"
completion: ^{
NSLog(@"Im Batman! |\_/|"); //using block
}}];
self.navigationController = [[UINavigationController alloc]
initWithRootViewController: controller];
self.navigationController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController: navigationController
animated: YES];
[controller back];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment