2017-09-21 38 views
0

我有一个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 "); 
} 
+0

请你出示代码? –

+0

与您的问题无关,但您应该使用“NSDictionary * dict = @ {@”Tags“:SearchTag};”创建你的字典。更新的语法更短,更易于阅读。 – ekscrypto

+0

正常工作,你打印这样的通知。 - (void)receivedNotification:(NSNotification *)notification {NSLog(@“%@”,notification.userInfo); NSLog(@“Notification Received”);} –

回答

0

当你didSelected一个单元格,并在发布的通知,但是另外的UIViewController不ALLOC这个时候,这样你就不会收到通知,

+0

我怎么称呼它? – meowsush

+0

你可以直接分配一个新的viewController而不需要通知 – taitanxiami

+0

我已经有了该视图控制器中的代码,只需将标签值传递给另一个viewcontroller来过滤 – meowsush