Created
March 8, 2019 13:06
-
-
Save mhmtkrgz/b5a58094397f26e7031c86097ba50b01 to your computer and use it in GitHub Desktop.
Delegate
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
#import <UIKit/UIKit.h> | |
@class SomeViewController; | |
@protocol SomeViewControllerDelegate <NSObject> | |
-(void)delegateMethodName:(SomeViewController *)controller; | |
@end | |
@interface SomeViewController : UIViewController | |
@property (nonatomic, weak) id<SomeViewControllerDelegate> delegate; | |
@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
#import "delegate.h" | |
@implementation SomeViewController | |
- (void)someMethodToCallDelegate { | |
if ([self.delegate respondsToSelector:@selector(delegateMethodName:)]) { | |
[self.delegate delegateMethodName:self]; | |
} | |
} | |
@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
#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