通知中心可以實(shí)現(xiàn)從后一個界面向前一個界面?zhèn)髦档墓δ堋#ㄟ@里認(rèn)為是從b界面向a界面?zhèn)髦担?/p>
第三個界面的代碼
NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@(downLoadProgress),@"progress",progressStr,@"progressStr",@(totalBytesExpectedToWrite),@"totalProgress", nil];
[[NSNotificationCenter defaultCenter] postNotificationName:@"ViewController" object:@"zhangsan" userInfo:dic];
從b界面發(fā)送一條通知铃岔,其中Name為第一個界面的名稱咬腋,object為要傳遞的值晚碾,如果使用單值傳遞掌挚,只需將所要傳的值賦給object即可姚炕,如果要使用多值傳遞掂器,可以將要傳遞的值放入一個字典亚皂,將值傳遞過去,object除了可以傳遞值之外国瓮,還可以作為標(biāo)識符灭必。
第一個界面的代碼
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self selector:@selector(receiveNotificiation:) name:@"ViewController" object:@"zhangsan"];
//通知中心的回調(diào)方法
- (void)receiveNotificiation:(NSNotification*)sender{
dispatch_async(dispatch_get_main_queue(), ^{
double progress = [[sender.userInfo objectForKey:@"progress"] doubleValue];
self.downLoadProgressView.progress = progress;
self.currentProgress_label.text = [sender.userInfo objectForKey:@"progressStr"];
});
}
//將通知中心移除
- (void)dealloc{
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"ViewController" object:@"zhangsan"];
}