Skip to content

Instantly share code, notes, and snippets.

@mhmtkrgz
Created March 8, 2019 13:06
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 mhmtkrgz/b5a58094397f26e7031c86097ba50b01 to your computer and use it in GitHub Desktop.
Save mhmtkrgz/b5a58094397f26e7031c86097ba50b01 to your computer and use it in GitHub Desktop.
Delegate
#import <UIKit/UIKit.h>
@class SomeViewController;
@protocol SomeViewControllerDelegate <NSObject>
-(void)delegateMethodName:(SomeViewController *)controller;
@end
@interface SomeViewController : UIViewController
@property (nonatomic, weak) id<SomeViewControllerDelegate> delegate;
@end
#import "delegate.h"
@implementation SomeViewController
- (void)someMethodToCallDelegate {
if ([self.delegate respondsToSelector:@selector(delegateMethodName:)]) {
[self.delegate delegateMethodName:self];
}
}
@end
#import "delegate.h"
@interface SomeDelegateUser () <SomeViewControllerDelegate> @end
@implementation SomeDelegateUser
- (void)variousFoo {
SomeViewController *controller = [[SomeViewController alloc] init];
controller.delegate = self;
}
-(void)delegateMethodName:(SomeViewController *)controller {
// handle the delegate being called here
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment