Created
June 14, 2012 07:30
-
-
Save roalcantara/2928732 to your computer and use it in GitHub Desktop.
Objective C Block Sample
This file contains 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
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 |
This file contains 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
@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 |
This file contains 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
@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