NotificationCenter 未在 CollectionViewCell 中调用 select
NotificationCenter not called in CollectionViewCell did select
我有一个用于显示一些标签的 collectionview 单元格,当我这样做时select 我必须使用 'NSNotificationCenter' 将标签名称发送给另一个 viewcontroller 来触发通知。但是当我 select collectioncell 中的一个标签时,通知被读取,但没有触发到另一个 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 ");
}
当你选择了一个单元格,你post一个通知,但是这次另一个 UIViewController 没有分配,所以你没有收到通知,
我有一个用于显示一些标签的 collectionview 单元格,当我这样做时select 我必须使用 'NSNotificationCenter' 将标签名称发送给另一个 viewcontroller 来触发通知。但是当我 select collectioncell 中的一个标签时,通知被读取,但没有触发到另一个 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 ");
}
当你选择了一个单元格,你post一个通知,但是这次另一个 UIViewController 没有分配,所以你没有收到通知,