简体   繁体   English

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

[英]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 . 我有一个collectionview单元格用于显示一些标签,当我执行didselect时,必须使用带有标签名称的'NSNotificationCenter'向另一个viewcontroller触发通知。 But when i select a label in collectioncell , The notification is read, but not triggered to another viewcontroller. 但是,当我在collectioncell中选择一个标签时,将读取通知,但不会将其触发到另一个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 ");
}

当您没有选择一个单元格并发布通知时,但是这次没有分配另一个UIViewController,因此您不会收到通知,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 NotificationCenter注册的选择器未调用 - NotificationCenter registered selector is not called 通知中心观察者未在 swift 4 中调用 - NotificationCenter obersever not called in swift 4 通过UIButton选择一个单元格-CollectionViewCell-Swift - Select a cell by UIButton - CollectionViewCell - Swift 如何选择CollectionViewCell内的TableViewCell - How can I select a TableViewCell that is inside a CollectionViewCell 观察者不会使用NotificationCenter Swift 4.0打电话 - Observers don't get called using NotificationCenter Swift 4.0 带有EKEventStoreChanged通知的NotificationCenter多次调用了不同的通知 - NotificationCenter with EKEventStoreChanged notification called multiple times with different notifications 当自定义collectionViewCell中有标签时,didSelectItemAtIndexPath不被调用 - didSelectItemAtIndexPath does not get called when a custom collectionViewCell has label in it IOS UITableView选择突出显示有时非常快,并且没有调用选择 - IOS UITableView Selection Highlight is sometimes very quick and did select is not being called 当我在SplitViewController的主视图中选择tableViewCell时未调用PrepareForSegue - PrepareForSegue is not being called when I did select a tableViewCell in SplitViewController's Master View NotificationCenter.default.addObserver 使用 Unwind Segue 不断被调用多次 - NotificationCenter.default.addObserver keep getting called multiple times with Unwind Segue
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM