未在CollectionViewCell中调用的NotificationCenter确实选择了

时间:2017-09-21 10:06:49

标签: ios objective-c nsnotificationcenter

我有一个集合视图单元格用于显示一些标签,当我选择时,我必须使用' NSNotificationCenter'来发布通知。将标签名称改为另一个viewcontroller。但是当我在集合单元格中选择标签时,会读取通知,但不会触发另一个视图控制器。任何人都可以建议我一个解决方案

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

1 个答案:

答案 0 :(得分:0)

当你选择了一个单元格,然后你发布了一个通知,但是这次没有分配另一个UIViewController,所以你没有收到通知,