NSString *const GameToIPhoneNotification = @"GameToIPhoneNotification"; GameToIPhoneNotification变量,@"GameToIPhoneNotification"这个值存于通知中心中,信息中心通过这个值来识别变量
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self selector:@selector(onToIphone:) name:GameToIPhoneNotification object:nil];
-(void)onToIphone:(NSNotification*)notify :这个方法是接受到GameToIPhoneNotification这个通知所调用的方法
2.调用信息
NSNotificationCenter * center = [NSNotificationCenter defaultCenter];
[center postNotificationName:GameToIPhoneNotification object:nil userInfo:[NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:SMSRecommendNotification] , @"actcode",nil]];
[NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:SMSRecommendNotification] 这个是传递给-(void)onToIphone:(NSNotification*)notify 的参数。
项目的聊天窗口遇到一个白屏的问题:
只要发送一个图片后,再发任何消息都导致聊天窗口白屏。
出问题的代码摘要如下:
//HWChatViewController.m - (void)viewDidLoad { [super viewDidLoad]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadChatCollectionViewData) name:HWCHAT_VIEW_NEED_RELOAD object:nil]; } -(void)reloadChatCollectionViewData { HWLog(@"111111*********"); yoho_dispatch_execute_in_main_queue(^{ HWLog(@"22222=========="); [_collectionView reloadData]; [_collectionView layoutIfNeeded]; HWLog(@"33333+++++++++++"); [_collectionView scrollToBottomAnimated:YES]; }); }
//HWChatManager.m -(void)reloadChatCollectionViewData { yoho_dispatch_execute_in_main_queue(^{ HWLog(@"抛通知HWCHAT_VIEW_NEED_RELOAD"); [[NSNotificationCenter defaultCenter] postNotificationName:HWCHAT_VIEW_NEED_RELOAD object:nil]; }); }
//HWPhotoMediaItem - (UIView *)mediaView { if (_cachedImageView == nil) { CGSize size = [self mediaViewDisplaySize]; UIImageView *imageView = [[UIImageView alloc] init]; NSURL *url = [NSURL URLWithString:_imageUrl]; if ([[url.scheme lowercaseString] isEqualToString:@"http"]) { [imageView sd_setImageWithURL:url completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { _size = image.size; yoho_dispatch_execute_in_main_queue(^{ HWLog(@"抛通知HWCHAT_VIEW_NEED_RELOAD"); [[NSNotificationCenter defaultCenter] postNotificationName:HWCHAT_VIEW_NEED_RELOAD object:nil]; }); }]; } else { //other code } //other code } return _cachedImageView; }
|[HWChatManager.m 175]: __45-[HWChatManager reloadChatCollectionViewData]_block_invoke 抛通知HWCHAT_VIEW_NEED_RELOAD
|[HWChatViewController.m 162]: -[HWChatViewController reloadChatCollectionViewData] 111111*********
|[HWChatViewController.m 164]: __52-[HWChatViewController reloadChatCollectionViewData]_block_invoke 22222==========
|[HWPhotoMediaItem.m 41]: __29-[HWPhotoMediaItem mediaView]_block_invoke_2 抛通知HWCHAT_VIEW_NEED_RELOAD
|[HWChatViewController.m 162]: -[HWChatViewController reloadChatCollectionViewData] 111111*********
|[HWChatViewController.m 164]: __52-[HWChatViewController reloadChatCollectionViewData]_block_invoke 22222==========
|[HWChatViewController.m 167]: __52-[HWChatViewController reloadChatCollectionViewData]_block_invoke 33333+++++++++++
|[HWChatViewController.m 167]: __52-[HWChatViewController reloadChatCollectionViewData]_block_invoke 33333+