![](/img/trans.png)
[英]How to pass data from viewcontroller to tabbarcontroller to navaigationcontroller?
[英]How to access the particular viewcontroller from the tabbarcontroller?
我有一個應用程序,其中有一個添加到應用程序窗口的tabbarcontroller。在tabbarcontroller中,我有兩個選項卡欄項目,每個項目都有導航控制器,在其中連接了相應的視圖控制器。現在,我需要訪問的實例變量標簽欄控制器中導航控制器內部的特定視圖控制器。我這樣做是沒有用的:
NSArray *mycontrollers = self.tabBarController.viewControllers;
NSLog(@"%@",mycontrollers);
self.secondviewcontroller=(SecondViewController *)[mycontrollers objectAtIndex:1];
self.secondviewcontroller.var=self.var;
但是它拋出了一些錯誤信息
-[UINavigationController setvar:]: unrecognized selector sent to instance
可以幫助我從該Navigationcontrollers的層次結構中找出如何實現特定視圖控制器的方法。
嘗試:
NSArray *mycontrollers = self.tabBarController.viewControllers;
NSLog(@"%@",mycontrollers);
UINavigationController *nvc = [mycontrollers objectAtIndex:1];
self.secondviewcontroller=(SecondViewController *)[nvc topViewController];
self.secondviewcontroller.var=self.var;
您的應用崩潰的原因是self.tabBarController.viewControllers;
正在返回導航控制器。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.