iOS注册系统通知

来源:互联网 发布:2018网络春晚策划方案 编辑:程序博客网 时间:2024/04/28 01:10

iOS编程里面,用到系统通知来接受事件是十分普遍的,最典型的就是键盘的通知事件。我们也可以自己定义通知的事件,让系统来调去我们想要的函数。


 // 注册通知

        [[NSNotificationCenter defaultCenteraddObserver:self 

                                                 selector:@selector(responseNotification:) 

                                                     name:DIQUN 

                                                   object:nil];

        

        [[NSNotificationCenter defaultCenteraddObserver:self 

                                                 selector:@selector(acceptNotification:) 

                                                     name:DIQUN

                                                   object:nil];


 // 实现通知的函数

- (void)responseNotification:(NSNotification *)notification

{

    A *render = (A *)notification.object;

}


 //发送通知
A *render ;

[[NSNotificationCenter defaultCenterpostNotificationName:DIQUN object:render];


这样就可以通过通知的形式,来调取我们需要的函数,来实现无对象引用的混合编程。