AnNSNotification有一个名为userInfothat is an的属性NSDictionary。object就是NSObject发布NSNotification. _ 所以通常我在设置时使用self,因为发送. 如果您希望通过using an我会执行以下操作:objectNSNotificationselfNSObjectNSNotificationNSArrayNSNotification
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"];
这总是对我有用。祝你好运!