I have parent view and child view.In child view i have a NSMutableDictionary .and i add values on it.then go back to parent view and want to get values that I added in child view, any one can describe with code. any idea??
3 Answers
create property in parentView.
And in child view code like below.
((parentView*)childView.superView).dic = dic;
may it help you.

- 898
- 11
- 28
-
how to get data from that dictionary in parent view ? – Kasun Sep 18 '12 at 11:17
Create an object for "ChildView" in "ParentView", then use the child object to access the NSMutableDictionary.
e.g:
//ParentViewController.m
ChildViewController *cvc = [[ChildViewController alloc]init];
NSDictionary *dict = cvc.myDict;

- 12,291
- 6
- 47
- 64

- 741
- 6
- 12
-
I added values to dictionary in child view, and go back to parent view and add this code in view will appir and access like this.but it is given null. AddMembersToCircleViewController *cvc = [[AddMembersToCircleViewController alloc]init]; NSDictionary *dict = cvc.selectedMembersDictionary; NSLog(@"dictionary%@",dict); – Kasun Sep 18 '12 at 13:02
The iVars are only accessible while the view is in the run loop. If it gets deallocated the iVar will be deallocated as well.
There are numerous ways to achieve what you are trying at.
One approach is to store global variables in your App Delegate, which are accessible through all views and the entire application run.
Another approach is, if you don't need the variable to be global accessible to use the NSNotificationCenter and subscribe for a notification.
The second approach is explained in this SO answer by me
Basically you can pass any value to the userInfo, so in your case you would be passing your Dictionary, this way:
[[NSNotificationCenter defaultCenter] postNotificationName:@"myNotification" object:self userInfo:MyDictionary];