Skip to content

Instantly share code, notes, and snippets.

@alfonsodev
Last active January 27, 2016 18:38
Show Gist options
  • Select an option

  • Save alfonsodev/9a99794443f969cba260 to your computer and use it in GitHub Desktop.

Select an option

Save alfonsodev/9a99794443f969cba260 to your computer and use it in GitHub Desktop.
objectivec delegates

notes taken from : https://www.youtube.com/watch?v=YVikeoR3gYg Communicating between two viewControllers

in the SecondViewController.m

  - (void)saveText {
    [self.delegate sendTextToViewController:@"name here"];
  }

in the SecondViewController.h

  @protocol CakeDelegate <NSObject>
    -(void)sendTextToViewControlller:(NSString *)string;
  @end
  @interface ...
  @property (nonatomic, weak) id<CakeDelegate>delegate;
  @end

in the HomeViewControlloer.h

  #import "SecondViewController.h"
  @interface HomeViewController : UIViewController <CakeDelegate>

in the HomeViewControlloer.m

-(void)sendTextToViewController:(NSString *)string {
  NSLog(string)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment