Skip to content

Instantly share code, notes, and snippets.

@ishida
Created November 16, 2012 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ishida/4086344 to your computer and use it in GitHub Desktop.
Save ishida/4086344 to your computer and use it in GitHub Desktop.
Objective-C Delegate
//
// AViewController.h
//
@protocol AViewControllerDelegate;
@interface AViewController : UIViewController <AViewControllerDelegate>
{
id <AViewControllerDelegate> delegate;
}
@property (nonatomic, retain) id <AViewControllerDelegate> delegate;
@end
@protocol AViewControllerDelegate <NSObject>
@optional
//- (void)delegateMethod;
@end
//
// AViewController.m
//
@implementation AViewController
@synthesize delegate;
- (void)aMethod
{
if (delegate && [delegate respondsToSelector:@selector(delegateMethod)])
{
[delegate delegateMethod];
}
}
@end
//
// BViewController.h
//
#import "AViewController.h"
@interface BViewController : UIViewController <AViewControllerDelegate> { }
@end
//
// BViewController.m
//
@implementation BViewController
- (void)delegateMethod
{
// process
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment