2017-09-21 29 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