Last active
December 4, 2015 13:44
-
-
Save 0xlitf/99aac529c8a064fa2f5e to your computer and use it in GitHub Desktop.
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
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeNavigationBarAlpha:) name:@"changeNavigationBarAlpha" object:nil]; | |
[[NSNotificationCenter defaultCenter] postNotificationName:@"changeNavigationBarAlpha" object:[NSString stringWithFormat:@"%f",a]]; | |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(callBack1:) name:@"PosterOne" object:nil]; | |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(callBack2:) name:@"PosterTwo" object:nil]; | |
-(void)callBack1:(NSNotification*)notification{ | |
NSString *nameString = [notification name]; | |
NSString *objectString = [notification object]; | |
NSLog(@"name = %@,object = %@",nameString,objectString); | |
} | |
-(void)callBack2:(NSNotification*)notification{ | |
NSString *nameString = [notification name]; | |
NSString *objectString = [notification object]; | |
NSDictionary *dictionary = [notification userInfo]; | |
NSLog(@"name = %@,object = %@,userInfo = %@",nameString,objectString,[dictionary objectForKey:@"key"]); | |
} | |
//1.下面两条语句等价 | |
//二者的区别是第一条语句是直接发送消息内容,第二条语句先创建一个消息,然后再发送消息 | |
[[NSNotificationCenter defaultCenter] postNotificationName:@"PosterOne" object:@"This is posterone!"]; | |
// [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:@"PosterOne" object:@"This is posterone"]]; | |
//2.下面两条语句等价 | |
//参数:userInfo --- Information about the the notification. | |
[[NSNotificationCenter defaultCenter] postNotificationName:@"PosterTwo" object:@"This is postertwo" userInfo:[NSDictionary dictionaryWithObject:@"value" forKey:@"key"]]; | |
// [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:@"PosterTwo" object:@"This is postertwo" userInfo:[NSDictionary dictionaryWithObject:@"value" forKey:@"key"]]]; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment