Search code examples
iosobjective-cnsnotificationcenter

NotificationCenter not called in CollectionViewCell did select


I have a collectionview cell for to display some labels, when I do didselect I have to fire a notification using 'NSNotificationCenter' with the label name to another viewcontroller . But when i select a label in collectioncell , The notification is read, but not triggered to another viewcontroller. Can anyone suggest me a solution

- (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 ");
}

Solution

  • When you didSelected a cell, and you post a notification ,but another UIViewController is not alloc this time , so you are not receive a notification,