这周用通知传值用的比较多,特此记录。

项目有三个主页面,一个语音,一个视频,一个我的

我的项目的需求是在语音页面点击下载按钮,我的页面的tableView就展示我所下载的此段音频。

1.在语音界面按钮点击事件里面

[[NSNotificationCenter defaultCenter] postNotificationName:@"refreshData" object:nil];

2.在我的页面createUI时,就是viewDidLoad时

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(update:) name:@"refreshData" object:nil];

3.在我的页面写上@selector(updata:)方法

- (void)update:(NSNotification *)notification {

    NSLog(@"接收通知--refreshData");


}

4.不要忘记在我的页面销毁通知

- (void)dealloc {

    [[NSNotificationCenter defaultCenter] removeObserver:@"refreshData"];
     
}

----------------------------------------------------------------------------

若要传值的话,object:后面可以接要传的参数,就像这样

[[NSNotificationCenter defaultCenter] postNotificationName:@"delArrayIndex" object:_dataArray];

获取这个参数:

-(void)updateArray:(NSNotification *)notification{
    
    
    _dataArr = notification.object;
   
    
    
}

也可以用这个方法传一个字典过去

- (void)postNotificationName:(NSNotificationName)aName object:(nullable id)anObject userInfo:(nullable NSDictionary *)aUserInfo;

👌

--------------------------------------------------------------------------------------------兰小妹

posted on 2018-03-17 18:39  兰歌er  阅读(153)  评论(1编辑  收藏  举报