读书人

NSNotificationCenter漫笔

发布时间: 2012-09-27 11:11:17 作者: rapoo

NSNotificationCenter随笔
可在AppDelegate.h中定义,之后可全局使用。

NSNotificationCenter *notificationCenter;

在.m文件中:

- (void)applicationDidFinishLaunching:(UIApplication *)application{    self.notificationCenter = [NSNotificationCenter defaultCenter];[notificationCenter addObserver:self selector:@selector(trackNotifications:) name:nil object:nil];}- (void) trackNotifications: (NSNotification *) notification{id nname = [notification name];if([nname isEqual:@"***"]){......}else if([nname isEqual:@"***"]){......}else if([nname isEqual:@"***"]){......}else if([nname isEqual:@"***"]){......}else if([nname isEqual:@"***"]){......}}


在别的地方使用的时候,只需要调用[[NSNotificationCenter defaultCenter] postNotificationName:@"about" object:@""];

读书人网 >移动开发

热点推荐