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