问题描述
我是iPhone开发的新手
I'm new with iphone development
我使用其视图控制器的tabbar和tabbaritems创建了情节提要
I created my storyboard with tabbar and tabbaritems with their viewcontroller
但是现在我想从uitabbarcontroller.m中访问viewcontroller实例.
but now I would like to access viewcontroller instances from my uitabbarcontroller.m
有人有带有示例代码的网址吗?
anybody have any url with code example?
我发现的代码非常易于使用或使用标签栏,大部分只是情节提要,对任何事情都无济于事...
the codes I find are very simple use or tabbar, mostly just the storyboard which doesn't help in anything...
谢谢
-在穆勒的帮助下解决方案
---solution after help from Muller
在uitabbarcontroller上:(我放置了一个断点,并能够检索视图控制器的集合)
on the uitabbarcontroller:(I placed a breakpoint and was able to retrieve the collection of viewcontrollers)
- (void)viewDidLoad
{
NSArray *arr = self.viewControllers;
}
推荐答案
您可以使用类似
NSArray *array = [tabBarControllerName viewControllers];
这将返回tabBarController中所有视图的数组,因此,如果您的第一个视图属于类,那么假设TestView我们可以做类似
This returns an array of all the views within your tabBarController, so if your first view is of class, let's say TestView we could do something like
TestView *tv = (TestView *)[array objectAtIndex:0];
请注意,这不在我的脑海中,所以可能有点不对劲.确保检查出Apple提供的类参考资料: UITabBarController类参考
Note that this is off the top of my head, so it may be a little off. Make sure you check out the class reference materials that apple provides: UITabBarController Class Reference
您真的可以像这样单行:
You could really just one-line it like this:
TestView *tv = (TestView *)[[tabBarControllerName viewControllers] objectAtIndex:0];
如果您通过以下方式在您的AppDelegate中声明了UITabBarController,则可以访问它:
You can access the UITabBarController if it is declared in your AppDelegate by:
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
TestView *tv = (TestView *)[[[appDelegate tabBarController] viewControllers] objectAtIndex:0];
这篇关于如何从uitabbarcontroller访问viewcontroller的任何代码示例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!