我有一個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 ");
}
請你出示代碼? –
與您的問題無關,但您應該使用「NSDictionary * dict = @ {@」Tags「:SearchTag};」創建你的字典。更新的語法更短,更易於閱讀。 – ekscrypto
正常工作,你打印這樣的通知。 - (void)receivedNotification:(NSNotification *)notification {NSLog(@「%@」,notification.userInfo); NSLog(@「Notification Received」);} –