2016-09-14 52 views
0

我想传递接口对象作为通知参数。传递接口对象作为通知对象

我有一个像

@interface StudentDetails : NSObject 
{ 
NSMutableArray* studentList; 
int   grade; 
} 
@end 

的接口,我想通过StudentDetails的对象作为通知参数如下图所示:

StudentDetails* pInterfaceCommand1 = [[StudentDetails alloc] init]; 
// student list is initialize to 1,2 & grade is 10 
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:pInterfaceCommand1 forKey:@"aKey"]; 

    [[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"testNotification" object:nil userInfo:userInfo deliverImmediately:YES]; 

但我不能够接收其他类的通知。 但是,当我张贴通知如下图所示,我能够接受的值为1

NSDictionary* userInfo = @{@"data": @1}; 
[[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"testNotification" object:nil userInfo:userInfo deliverImmediately:YES]; 

请让我知道需要什么样的变化。

+2

您没有收到通知,或者您没有收到有效负载? – Avi

+0

嗨。 1.未收到以下情况的通知 StudentDetails * pInterfaceCommand1 = [[StudentDetails alloc] init]; NSDictionary * userInfo = [NSDictionary dictionaryWithObject:pInterfaceCommand1 forKey:@“aKey”]; [[NSDistributedNotificationCenter defaultCenter] postNotificationName:@“testNotification”object:nil userInfo:userInfo deliverImmediately:YES]; 2.接收回应 NSDictionary * userInfo = @ {@“data”:@ 1}; 。 [[NSDistributedNotificationCenter defaultCenter] postNotificationName:@“testNotification”object:nil userInfo:userInfo deliverImmediately:YES]; – Phillip

+0

可以'StudentDetails'被序列化吗? – Willeke

回答

0

您的代码使用的是NSDistributedNotificationCenter,这是不寻常的。你真的想把通知发送到不同的过程吗?如果需要接收通知的对象在同一个程序中,则通常使用NSNotificationCenter

+0

嗨。 谢谢你的回复。 我需要NSDistributedNotificationCenter,因为应用程序正在向不同的进程发送通知 – Phillip