2012-09-18 116 views

回答

0

在parentView中創建屬性。

並在子視圖代碼如下。

((parentView*)childView.superView).dic = dic; 

它可以幫助你。

+0

如何獲取數據從父視圖中的字典? – Kasun

0

在「ParentView」中爲「ChildView」創建一個對象,然後使用子對象訪問NSMutableDictionary。

e.g:

//ParentViewController.m 
ChildViewController *cvc = [[ChildViewController alloc]init]; 
NSDictionary *dict = cvc.myDict; 
+0

我將值添加到子視圖中的字典中,並返回父視圖,並在視圖中添加此代碼將appir和像這樣訪問,但它被賦予null。 AddMembersToCircleViewController * cvc = [[AddMembersToCircleViewController alloc] init]; NSDictionary * dict = cvc.selectedMembersDictionary; NSLog(@「dictionary%@」,dict); – Kasun

0

實例變量是唯一可同時視圖在運行循環。 如果它被釋放,iVar也將被釋放。

有很多方法可以實現您的嘗試。

一種方法是將全局變量存儲在您的App Delegate中,這些變量可通過所有視圖和整個應用程序運行。

另一種方法是,如果您不需要該變量是全局可訪問的,則可以使用NSNotificationCenter並訂閱通知。

第二種方法是在這個SO answer by me

解釋基本上可以將任何值傳遞給用戶信息,所以你的情況,你會通過你的解釋,是這樣的:

[[NSNotificationCenter defaultCenter] postNotificationName:@"myNotification" object:self userInfo:MyDictionary]; 
相關問題