Skip to content

Instantly share code, notes, and snippets.

@fozoglu
Created March 20, 2015 13:05
Show Gist options
  • Save fozoglu/41b52b87503e19ad536e to your computer and use it in GitHub Desktop.
Save fozoglu/41b52b87503e19ad536e to your computer and use it in GitHub Desktop.
NSNotification_Example
#import <UIKit/UIKit.h>
#import "ViewController.h"
@interface FirstMenuViewController : UIViewController
- (IBAction)sendValue:(id)sender;
@end
#import "FirstMenuViewController.h"
@interface FirstMenuViewController ()
@property (nonatomic, strong) ViewController *viewcontroller;
@end
@implementation FirstMenuViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
- (IBAction)sendValue:(id)sender {
if (nil == self.viewcontroller) {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
self.viewcontroller = [storyboard instantiateViewControllerWithIdentifier:@"viewcontroller"];
self.viewcontroller.Name = @"tutorial";
}
[[NSNotificationCenter defaultCenter]postNotificationName:@"NameNotification" object:nil];
}
@end
#import <UIKit/UIKit.h>
#import "FirstMenuViewController.h"
@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *lblName;
@property (nonatomic, copy) NSString *Name;
@end
#import "ViewController.h"
@interface ViewController (){
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showName) name:@"NameNotification" object:nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)showName{
self.lblName.text = self.Name;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment