2013-08-05 40 views
0

訪問容器視圖控制器我有一個父視圖控制器和兩個容器中這樣說:從另一個容器視圖控制器

UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; 
MyCombinationsViewController *myComb = [storyboard instantiateViewControllerWithIdentifier:@"MyCombinationsViewControllerID"]; 
myComb.view.frame = self.combinationsContainer.bounds; 
[self.combinationsContainer addSubview:myComb.view]; 
[self addChildViewController:myComb]; 
[myComb didMoveToParentViewController:self]; 

StatInfoViewController *stat = [storyboard instantiateViewControllerWithIdentifier:@"StatInfoViewControllerID"]; 
stat.view.frame = self.statContainer.bounds; 
[self.statContainer addSubview:stat.view]; 
[self addChildViewController:stat]; 
[stat didMoveToParentViewController:self]; 

我想要做內部StatInfoViewController是影響MyCombinationsViewController東西。我如何訪問MyCombinationsViewController屬性而不重新分配它?

這樣做:

UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; 
MyCombinationsViewController *myComb = [storyboard instantiateViewControllerWithIdentifier:@"MyCombinationsViewControllerID"]; 

StatInfoViewController返回空屬性,當我嘗試做一些像NSLog(@"%@",myComb.something);

+0

使用NSNotificationCenter訪問myCombinationsViewController如果兩個集裝箱都沒有關係。 – Tirth

回答

0

你可以在StatInfoViewController的頭togehter它們連接,通過添加:

@property (nonatomic, weak) MyCombinationsViewController* myCombinationsViewController 

然後在分配它們時執行以下操作:

StatInfoViewController *stat = [storyboard instantiateViewControllerWithIdentifier:@"StatInfoViewControllerID"]; 
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; 
MyCombinationsViewController *myComb = [storyboard instantiateViewControllerWithIdentifier:@"MyCombinationsViewControllerID"]; 

stat.myCombinationsViewController = myComb; 


myComb.view.frame = self.combinationsContainer.bounds; 
[self.combinationsContainer addSubview:myComb.view]; 
[self addChildViewController:myComb]; 
[myComb didMoveToParentViewController:self]; 

stat.view.frame = self.statContainer.bounds; 
[self.statContainer addSubview:stat.view]; 
[self addChildViewController:stat]; 
[stat didMoveToParentViewController:self]; 

然後,你可以從裏面StatInfoViewController

相關問題