在 Cocoa 中引用父级

发布于 2024-08-02 19:12:20 字数 361 浏览 1 评论 0原文

我的问题是关于如何从 TabBarController 的一个视图控制器中访问 TabBarController 。

想象一下 mainClass.m 添加了 tabBarController,它有两个 viewController - viewController1 和 viewController2。

在viewController1.m中有一个游戏。当游戏结束时,viewController1.m想要告诉tabBarController显示viewController2,但是viewController1没有引用tabBarController。如何引用 viewController 的父级?

如何从当前视图的代码中更改 tabBarItems?

My question is about how to access the TabBarController from within one of its viewControllers.

Imagine a mainClass.m that adds tabBarController which has two viewControllers - viewController1 and viewController2.

In viewController1.m there is a game. When the game is over, viewController1.m wants to tell tabBarController to display viewController2, but viewController1 has no reference to tabBarController. How do I reference the viewController's parent?

How does one change tabBarItems from within the code for the current view?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晒暮凉 2024-08-09 19:12:20

通过视图控制器的 tabBarController 属性。

[ self.tabBarController setViewControllers: viewController2 animated: YES ];

其中“self”是 viewController1

viewControllers 的 tabController 属性

setViewControllers:animated: UITabBarController 的方法

另外,从技术上讲,tabBarController 不是任何视图控制器的父级。这样说是令人困惑的 Objective-C 中的继承是如何工作的。您的视图控制器的超类或父类是 UIViewController。

Via the tabBarController property of your view controller.

[ self.tabBarController setViewControllers: viewController2 animated: YES ];

Where "self" is viewController1

tabController property of viewControllers

setViewControllers:animated: method of UITabBarController

Also, technically, the tabBarController is not any view controller's parent. To say it that way is confusing how inheritance works in Objective-C. Your view controller's super class, or parent, is UIViewController.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文