@implementation MyObject// posts a MyNotification message whenever called- (voID)notify { [[NSNotificationCenter defaultCenter] postNotificationname:@"MyNotification" object:self];}// Prints a message whenever a MyNotification is received- (voID)handleNotification:(NSNotification*)note { NSLog(@"Got notifIEd: %@",note);}@end// somewhere elseMyObject *object = [[MyObject alloc] init];// receive MyNotification events from any object[[NSNotificationCenter defaultCenter] addobserver:object selector:@selector(handleNotification:) name:@"MyNotification" object:nil];// create a notification[object notify];
有关详细信息,请参阅NSNotificationCenter的文档。
总结以上是内存溢出为你收集整理的objective-c – Cocoa自定义通知示例全部内容,希望文章能够帮你解决objective-c – Cocoa自定义通知示例所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)