主要函数、方法

//
+ (id)defaultCenter; //增加通知事件 - (void)addObserver:(id)observer selector:(SEL)aSelector name:(NSString *)aName object:(id)anObject; //类似于接受开始通知事件 - (void)postNotification:(NSNotification *)notification; - (void)postNotificationName:(NSString *)aName object:(id)anObject; - (void)postNotificationName:(NSString *)aName object:(id)anObject userInfo:(NSDictionary *)aUserInfo; //移除通知 - (void)removeObserver:(id)observer; - (void)removeObserver:(id)observer name:(NSString *)aName object:(id)anObject;

 

实例:

//在mainviewcontroller中添加观察者

 //接受编辑/完成通知
    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(setEditButtonOn)
                                                 name:@"SETEDITBUTTONON"
                                               object:nil];
   
    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(setEditButtonOff)
                                                 name:@"SETEDITBUTTONOFF"
                                               object:nil];
//通知触发的事件
-(void)setEditButtonOn{
    self.editButton.selected = YES;
}

- (void)setEditButtonOff{
    self.editButton.selected = NO;
}
//发送编辑通知
    [[NSNotificationCenter defaultCenter] postNotificationName:
     @"SETEDITBUTTONON" object:nil];

//最后移除观察者
  [[NSNotificationCenter defaultCenter]removeObserver:self name:@"SETEDITBUTTONON" object:nil];

相关文章:

  • 2021-07-24
  • 2021-08-04
  • 2021-08-06
  • 2021-08-26
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-16
  • 2022-12-23
  • 2021-06-05
  • 2022-12-23
  • 2022-12-23
  • 2021-09-24
相关资源
相似解决方案