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];
请让我知道需要什么样的变化。
您没有收到通知,或者您没有收到有效负载? – Avi
嗨。 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
可以'StudentDetails'被序列化吗? – Willeke