AnNSNotification
有一个名为userInfo
that is an的属性NSDictionary
。object
就是NSObject
发布NSNotification
. _ 所以通常我在设置时使用self
,因为发送. 如果您希望通过using an我会执行以下操作:object
NSNotification
self
NSObject
NSNotification
NSArray
NSNotification
NSArray *myArray = ....;
NSDictionary *theInfo =
[NSDictionary dictionaryWithObjectsAndKeys:myArray,@"myArray", nil];
[[NSNotificationCenter defaultCenter] postNotificationName:@"reloadData"
object:self
userInfo:theInfo];
然后使用以下命令捕获它:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(doTheReload:)
name:@"reloadData"
object:sendingObject];
sendingObject
发送NSNotification
. _
最后,doTheReload:
使用以下方法解码数组:
NSArray *theArray = [[notification userInfo] objectForKey:@"myArray"];
这总是对我有用。祝你好运!