我有一个collectionview单元格来显示一些标签,当我做selectselect时,我必须使用带有标签名称的'NSNotificationCenter'向另一个viewcontroller发出通知。但是,当我在collectioncell中选择一个标签时,通知被读取,但不会触发到另一个viewcontroller。任何人都可以给我建议的解决方案在CollectionViewCell中没有调用的NotificationCenter没有选择
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
NSString *SearchTag;
for(int i = 0; i < (int)[_taglinkarray[indexPath.row] count] ; i++)
{
if([[_taglinkarray[indexPath.row][i] valueForKey:@"profileFieldType"] isEqualToString:@"certificate"])
{
SearchTag = _tagarray[indexPath.row];
NSLog(@"tag name ------->%@",_tagarray[indexPath.row]);
NSDictionary * dict =[NSDictionary dictionaryWithObject:SearchTag forKey:@"Tags"];
[[NSNotificationCenter defaultCenter] postNotificationName:@"NOTIFICATION" object:nil userInfo:dict];
}
}
}
In Another VC
//In DidLoad()
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(receivedNotification:)
name:@"NOTIFICATION" object:nil];
-(void)receivedNotification:(NSNotification*) notification
{
NSLog(@"Notification Received ");
}
请你出示代码? –
与您的问题无关,但您应该使用“NSDictionary * dict = @ {@”Tags“:SearchTag};”创建你的字典。更新的语法更短,更易于阅读。 – ekscrypto
正常工作,你打印这样的通知。 - (void)receivedNotification:(NSNotification *)notification {NSLog(@“%@”,notification.userInfo); NSLog(@“Notification Received”);} –