I could do this by using protocol and delegate but I would like to try with NSNotification
My task is sending an NSMutableArray via notification from one to another view. Is it possible to do
[[NSNotificationCenter defaultCenter] postNotificationName:@"reloadData" object:myArray];
Then, in the receiver, how can I get the passed myArray. I was reading and confused about the userInfo and object of notification object.
Please advice me on this issue.
An
NSNotificationhas a property calleduserInfothat is anNSDictionary. Theobjectis theNSObjectthat is posting theNSNotification. So usually I useselffor theobjectwhen I’m setting up theNSNotificationbecauseselfis theNSObjectsending theNSNotification. If you wish to pass anNSArrayusing anNSNotificationI would do the following:And then catch it using the following:
where
sendingObjectis the object that is sending theNSNotification.Finally, decode the array in
doTheReload:using:That always works for me. Good luck!