Created
March 3, 2016 08:37
-
-
Save wisaruthk/44b27079f3df7a95c0dc to your computer and use it in GitHub Desktop.
Demo NSNotification
This file contains hidden or 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
// | |
// FirstViewController.m | |
// NotifDemo | |
// | |
// Created by wisaruthk on 3/3/2559 BE. | |
// Copyright © 2559 kojo. All rights reserved. | |
// | |
#import "FirstViewController.h" | |
#import "Children.h" | |
@interface FirstViewController () | |
@end | |
@implementation FirstViewController | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
// Do any additional setup after loading the view, typically from a nib. | |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateView:) name:@"IM_UPDATE" object:nil]; | |
} | |
- (void)didReceiveMemoryWarning { | |
[super didReceiveMemoryWarning]; | |
// Dispose of any resources that can be recreated. | |
} | |
/* | |
* สามารถส่งข้าม VC ได้ | |
*/ | |
- (IBAction)doAction:(id)sender { | |
Children *a = [[Children alloc] init]; | |
a.name = @"Josep"; | |
[[NSNotificationCenter defaultCenter] postNotificationName:@"IM_UPDATE" object:a]; | |
} | |
- (void)updateView:(NSNotification*)sender{ | |
NSLog(@"FirstVC receive notif "); | |
Children *c = (Children*)sender.object; | |
NSLog(@"name=%@",c.name); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment