xcode – 从UIViewcontroller链接到UITabBarController页面

前端之家收集整理的这篇文章主要介绍了xcode – 从UIViewcontroller链接到UITabBarController页面前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个链接问题,使用xib,而不是故事板.

我有一个UITabBarController系统和一些远离标签栏系统的其他视图控制器.我的问题是我可以使用按钮将其中一个视图控制器链接回UITabBarController上的某个页面吗?

解决方法

UITabBarController是父级,选项卡下的ViewControllers是子级.您可以使用parentViewController属性从childViewControllers访问TabBarController.

因此,如果你有一个带有2个选项卡的UITabBarController,它们包含ViewController1和ViewController2,你可以在其中任何一个中使用这一行.

UITabBarController* tabBarController = (UITabBarController*)self.parentViewController;
// So if for example you have a button in ViewController2 and you need to show
// ViewController1 when it is pressed,you can do the following
tabBarController.selectedIndex = 0;

猜你在找的Xcode相关文章